top of page

C++ | Function Overloading

Function overloading is a feature in C++ where two or more functions can have the same name but different parameters. Function overloading can be considered as an example of a polymorphism feature in C++.


#include<iostream.h>
#include<conio.h>
int time=1;
float rate=2;
void calcint(float prin)
{
float interest=(prin*rate*time)/100;
cout<<"\n One Argument function"<<interest<<endl;
}
void calcint(float prin,float rate)
{
float interest=(prin*rate*time)/100;
cout<<"\n Two Argument function"<<interest<<endl;
}
void calcint(float prin,float rate,int time)
{
float interest=(prin*rate*time)/100;
cout<<"\n Three Argument function"<<interest<<endl;
}

void main()
{
clrscr();
int t;
float p,r;
cout<<"\n Enter principle, rate and time:";
cin>>p>>r>>t;
calcint(p);
calcint(p,r);
calcint(p,r,t);
getch();
}

Output:

Enter principle, rate and time: 1200
3
4
One Argument function 24
Two Argument function 36
Three Argument function 144
 

Happy Coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor

Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem. Follow Programmers Door for more. #blog #interview #placement #learn #computer #science

11 views0 comments

Recent Posts

See All
bottom of page