Write A C++ Program To Implement The Default Argument And Default Argument With Output
Ex: No: 1(a) FUNCTION OVERLOADING
Aim : To write a c ++ program to implement the function overloading
Algorithm:
Step 1: Start a program.
Step 2: Declare the function variable.
Step 3: Invoke the main function in that of the set and value.
Step 4: Declare the function area.
Step 5: Display the data given.
Step 6: Stop the program.
Program:
#include
#include
int volume(int);
doublevolume(int);
long volume(long,int,int);
int main()
{
clrscr();
cout<
cout<
cout<
getch();
}
int volume(int s)
{
return(s*s*s);
}
double volume(double r,int h)
{
return(3.14*r*r*h);
}
long volume(long l,int b,int h)
{
return(l*b*h);
}
Algorithm:
Step 1: Start a program.
Step 2: Declare the function variable.
Step 3: Invoke the main function in that of the set and value.
Step 4: Declare the function area.
Step 5: Display the data given.
Step 6: Stop the program.
Program:
#include
#include
int volume(int);
doublevolume(int);
long volume(long,int,int);
int main()
{
clrscr();
cout<
cout<
cout<
getch();
}
int volume(int s)
{
return(s*s*s);
}
double volume(double r,int h)
{
return(3.14*r*r*h);
}
long volume(long l,int b,int h)
{
return(l*b*h);
}
Output:
1000
80
112500
Result:
Thus the implementation of c ++ program for function overloading is executed and the output has been verified.
Aim:To write a c ++ program to implement the default argument
Algorithm:
Step 1: Start the program.
Step 2: Declare the simple interest function with default argument.
Step 3: From main function call the required data.
Step 4: Define simple interest function.
Step 5: Calculating simple interest.
Step 6: Display the details given.
Step 7: Stop the program.
1000
80
112500
Result:
Thus the implementation of c ++ program for function overloading is executed and the output has been verified.
Ex: No: 1(b) DEFAULT ARGUMENT IN C++
Aim:To write a c ++ program to implement the default argument
Algorithm:
Step 1: Start the program.
Step 2: Declare the simple interest function with default argument.
Step 3: From main function call the required data.
Step 4: Define simple interest function.
Step 5: Calculating simple interest.
Step 6: Display the details given.
Step 7: Stop the program.
Program:
#include
#include
float si(float=1000.00,int=2,float=0.02);
void main()
{
clrscr();
float p,r;
int n;
cout<<"\n enter principle:";
cin>>p;
cout<<"\n enter number of year:";
cin>>n;
cout<<"\n enter rate of interest:";
cin>>r;
cout<<"\n default argument p=1000.00,n=2,&r=0.02";
cout<<"\n simple interest si()="<
cout<<"\n simple interest si(p)="<
cout<<"\n simple interest si(p,n)="<
cout<<"\n simple interest si(p,n,r)="<
getch();
}
float si(float pr,int no,float ra)
{
return((pr*no*ra)/pr);
}
#include
float si(float=1000.00,int=2,float=0.02);
void main()
{
clrscr();
float p,r;
int n;
cout<<"\n enter principle:";
cin>>p;
cout<<"\n enter number of year:";
cin>>n;
cout<<"\n enter rate of interest:";
cin>>r;
cout<<"\n default argument p=1000.00,n=2,&r=0.02";
cout<<"\n simple interest si()="<
cout<<"\n simple interest si(p)="<
cout<<"\n simple interest si(p,n)="<
cout<<"\n simple interest si(p,n,r)="<
getch();
}
float si(float pr,int no,float ra)
{
return((pr*no*ra)/pr);
}
Output:
Enter Principle: 100
Enter number of year: 2011
Enter rate of interest: 10
Default argument P= 1000.00, n=2 & r=0.02
Simple interest Si () =0.04
Simple interest Si (p) =0.04
Simple interest Si (p, n) =40.219997
Simple interest Si (p, n, r) =20110
Enter Principle: 100
Enter number of year: 2011
Enter rate of interest: 10
Default argument P= 1000.00, n=2 & r=0.02
Simple interest Si () =0.04
Simple interest Si (p) =0.04
Simple interest Si (p, n) =40.219997
Simple interest Si (p, n, r) =20110
Result:
Thus the implementation of c ++ program for default argument is executed and the output has been verified.
Thus the implementation of c ++ program for default argument is executed and the output has been verified.
0 comments:
Post a Comment