Need a project done?

C++ Programming Developer

Search This Blog

Function Overloading in C++


Example of Function Overloading in C++:

#include <iostream>
using std::cout;
using std::endl;

class a{
public:
long double p_calculateArea(double);
private:
long double calculateArea(double);
};
long double p_a::calculateArea(double r){
return (calculateArea(r));
}
long double a::calculateArea(double r){
return (3.14159265359*r*r);
}
int main(){
a obj;
while (1){
cout << "Choice = 1, to calculate area of circle from the taken input arguments."
<< "\nChoice = 2, to calculate area of circle from the taken input arguments."
<< "\nChoice = 3, to calculate area of triangle from the taken input arguments."
<< "\nChoice = 4, Exit the Program.
int opt; cin >> opt;
switch(opt){
case 1:
cout << "Radius of Circle: "; double r; cin >> r;
cout << "Area of Circle: " << obj.p_calculateArea(r) << endl;
break;
case 2:

}
a::a(){
ID++;
}
int getUniqueID(){
return ID;
}

No comments:

Post a Comment

"Don't let anyone ever make you feel like you don't deserve what you want."