In this article we will look at implementing a CPP program to demonstrate the use of default arguments. A C++ program is provided below to illustrate the use of default arguments for simple interest function. Program is as follows:
#include <iostream>
using namespace std;
float si(int p, int n, int r=5)
{
return (p*n*r)/100;
}
int main()
{
int p, n, r;
cout<<"Enter principal amount: ";
cin>>p;
cout<<"Enter duration (in years): ";
cin>>n;
cout<<"Enter rate of interest: ";
cin>>r;
cout<<"Simple interest = "<<si(p, n, r);
cout<<"Simple interest = "<<si(p, n);
return 0;
}
Input and output for the above program are as follows:
Enter principal amount: 10000
Enter duration (in years): 5
Enter rate of interest: 10
Simple interest = 5000
Simple interest = 2500
Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.
He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.
He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.
Leave a Reply