Answer to Question #198863 in C++ for Ali raza

Question #198863

Write overloaded constructors that take different arguments and calculates the area of shape as well as displays it.


1
Expert's answer
2021-05-28T06:16:32-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog