Question: C + + #include using namespace std ; class Polygon { protected: int width, height ; public: void setValues ( int w , int h

C++ #include
using namespace std ;
class Polygon
{
protected:
int width, height ;
public:
void setValues( int w, int h ){ width = w ; height = h ; }
} ;
class Rectangle: public Polygon
{
public:
int area(){ return ( width * height ) ; }
} ;
class Triangle: public Polygon
{
public:
int area(){ return (( width * height )/2) ; }
} ;
int main()
{
Rectangle rect ; rect.setValues(4,5) ;
Triangle trgl ; trgl.setValues(4,5) ;
cout << "Rectangle area : "<< rect.area()<< endl ;
cout << "Triangle area : "<< trgl.area()<< endl ;
return 0 ;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!