#include <iostream>
class Rectangle {
protected:
int width;
int height;
public:
Rectangle(int width = 0, int height=0) {
this->width = width;
this->height = height;
}
void display() {
std::cout << width << " " << height<<std::endl;
}
};
class RectangleArea : public Rectangle {
public:
RectangleArea() {}
RectangleArea(int width, int height) :Rectangle(width, height) {}
void read_input() {
std::cout << "Enter width of rectangle: ";
std::cin >> this->width;
std::cout << "Enter height of rectangle: ";
std::cin >> this->height;
}
void display() {
std::cout << this->width*this->height << std::endl;
}
};
int main() {
Rectangle* rectangle = new Rectangle(1,2);
rectangle->display();
RectangleArea *rectangleArea = new RectangleArea();
rectangleArea->read_input();
rectangleArea->display();
system("pause");
return 0;
}
Comments
Leave a comment