Question: #include using namespace std; // Base class Shape class Shape { public: void setWidth(int w) { width = w; } void setHeight(int h) { height

#include using namespace std;

// Base class Shape class Shape { public: void setWidth(int w) { width = w; } void setHeight(int h) { height = h; }

protected: int width; int height; };

// Base class PaintCost class PaintCost { public: int getCost(int area) { return area * 70; } };

// Base class PaintCost class DrawShape :public Shape { public: void ShapeDrawing() { cout << " "; //drawing the top of the rectangle for (int a = 0; a < width; a++) cout << "--";

cout << " ";//starting on a new line for (int a = 0; a <= height - 2; a++)// Printing both sides of the rectangle { cout << "|";//The left side for (int b = 0; b <= width - 2; b++)//The space between the left and rigth side cout << " "; cout << "| ";//The Rigth side, and creating the new line } for (int a = 0; a < width; a++) //drawing the bottom of the rectangle cout << "--"; cout << " "; } };

// Derived class class Rectangle : public PaintCost, public DrawShape { public: int getArea() { return (width * height); } };

int main() { Rectangle Rect;

int area;

Rect.setWidth(25); Rect.setHeight(5); Rect.ShapeDrawing();

area = Rect.getArea();

// Print the area of the object. cout << "Total area: " << Rect.getArea() << endl;

// Print the total cost of painting cout << "Total paint cost: $" << Rect.getCost(area) << endl; system("pause"); return 0; }

//Using the provided code, Create a class called "Triangle" and derive it from the base class Shape and any other base class.

//Create a public function called DrawTriangle to draw the shape.

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 Databases Questions!