write a C++ program that calculates the area of a rectangular shaped wall and th
ID: 3913890 • Letter: W
Question
write a C++ program that calculates the area of a rectangular shaped wall and then calculates the required cost to paint that wall. It costs $50 per unit area to paint. write a C++ code using public inheritance. The base class named "shape" will have height and width as protected data. it should also have necessary constructor, set and get functions. The derived class named "Rectangle" will calculate the area of the rectangle. finally in th3 main function calculate the cost to paint the wall.
need help with C++ assignment for homework at city college.
Gracias!!
Explanation / Answer
#include <iostream>
using namespace std;
class Shape {
protected:
double height;
double width;
public:
Shape(double height, double width) {
this->height = height;
this->width = width;
}
double getHeight() {
return height;
}
double getWidth() {
return width;
}
void setHeight(double height) {
this->height = height;
}
void setWidth(double width) {
this->width = width;
}
};
class Rectangle : public Shape {
public:
Rectangle(double height, double width) :Shape(height, width) {
}
double getArea() {
return height * width;
}
};
// declare the main function
int main() {
double height, width;
cout << "Enter the height: ";
cin >> height;
cout << "Enter the width: ";
cin >> width;
Rectangle object(height, width);
double area = object.getArea();
cout << "Area of rectangle = " << area << " ";
cout << "Total cost of painting: $" << area * 50 << " ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.