Create a C++ class overload to perform following functions: float area(float,float,float) – returns the area of cone. float area(float, float) – returns the area of sphere. float area( int) – returns the area of circle.
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio>
#include<iostream>
#include<math.h>
class overload
{
float m,n;
public:
float area(float r,float h,float pi)
{
m=sqrt(h*h+r*r);
n=r+m;
return(pi*r*n);
}
float area(float r,float pi) // function overloading
{
return(4*pi*r*r);
}
float area(int r) // function overloading
{
int pi=3.142;
return(pi*r*r);
}
};
int main()
{
overload obj; // object created
float pi;
pi=3.142;
cout<<"area of cone: "<<obj.area(2.4,3.1,pi)<<endl;
cout<<"area of sphere: "<<obj.area(2.2,3.142)<<endl;
cout<<"area of circle: "<<obj.area(2)<<endl;
getch();
return(0);
}
0 Comments