Answer to Question #199004 in C++ for haider

Question #199004

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



1
Expert's answer
2021-05-26T12:57:15-0400
#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;
}








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