1. Write overloaded constructors that take different arguments and calculates the area of shape as well as displays it.
#include <iostream>
#include <string>
using namespace std;
class Shape{
public:
Shape(float r){
double area=3.14*r*r;
cout<<"Area of Circle: "<<area<<endl;
}
Shape(float width,float height){
float area=width*height;
cout<<"Area of Rectangle: "<<area<<"\n";
}
Shape(float a,float b,float fac){
float area=fac*a*b;
cout<<"Area of Triangle: "<<area<<endl;
}
};
int main() {
Shape circle(10);
Shape rectangle(10,5);
Shape triangle(5,6,0.5);
system("pause");
return 0;
}
Comments
Leave a comment