0% found this document useful (0 votes)
23 views3 pages

Write A Program To Show An Example of Working of Default Arguments

This C++ program demonstrates the use of default arguments in a function. The amount() function calculates interest and takes principal, time, and interest rate as arguments, with default values of 2 years and 8% for time and rate respectively. The main() function calls amount() four times with different argument values to show the effect of default arguments.

Uploaded by

sdave1604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Write A Program To Show An Example of Working of Default Arguments

This C++ program demonstrates the use of default arguments in a function. The amount() function calculates interest and takes principal, time, and interest rate as arguments, with default values of 2 years and 8% for time and rate respectively. The main() function calls amount() four times with different argument values to show the effect of default arguments.

Uploaded by

sdave1604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

________________________________

Write a program to show an example of working of default


arguments.

#include<iostream.h>
#include<conio.h>


void amount(float princ, int time=2, float rate=0.08)
{
cout<<\nPrincipal amount :<<princ;
cout<<\nTime :<<time<< years;
cout<<\nRate :<<rate;
cout<<\nIntrest amount :<<(princ*rate*time)<<\n;
}

void main()
{
system(cls);
cout<<\nCase1:;
amount(2000);
cout<<\nCase 2:;
amount(2500,3);
cout<<\nCase3:;
amount(2300,3,0.11);
cout<<\nCase4:;
amount(2500,0.12);
getch();
}


Output:
Case 1:
Principal amount: 2000
Time: 2
Rate: 0.08
Interest amount: 320



Case 2:
Principal amount: 2500
Time: 3
Rate: 0.08
Interest amount: 600

Case 3:
Principal amount: 2300
Time: 3
Rate: 0.11
Interest amount: 759

Case 4:
Principal amount: 2500
Time: 0
Rate: 0.08
Interest amount: 0

You might also like