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(double radius){
double area=3.142*radius*radius;
cout<<"Area of Circle is: "<<area<<endl;
}
Shape(double width,double height){
double area=width*height;
cout<<"Area of Rectangle: "<<area<<endl;
}
Shape(double a,double b,double f){
double area=f*a*b;
cout<<"Area of Triangle: "<<area<<endl;
}
};
int main() {
Shape circle(25);
Shape rectangle(15,12);
Shape triangle(16,17,23);
return 0;
}
Comments
Leave a comment