1
0

14_rectangle.cpp 585 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <iostream>
  2. using namespace std;
  3. class Poly
  4. {
  5. protected:
  6. int width;
  7. int height;
  8. public:
  9. Poly(int w, int h) { set_size(w, h); }
  10. void set_size(int w, int h)
  11. {
  12. width = w;
  13. height = h;
  14. }
  15. int get_width() { return width; }
  16. int get_height() { return height; }
  17. };
  18. class Rectangle : public Poly
  19. {
  20. public:
  21. Rectangle(int w, int h) : Poly(w, h) {}
  22. int area() { return width * height; }
  23. };
  24. int main()
  25. {
  26. Rectangle x(10, 20);
  27. cout << "Area of rectangle with sides length " << x.get_width() << " and "
  28. << x.get_height() << " is " << x.area() << endl;
  29. return 0;
  30. }