1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 #include <iostream>
5 
6 using namespace std;
7 
8 class Shape {
9   public:
setWidth(int w)10     void setWidth(int w) { width = w; }
setHeight(int h)11     void setHeight(int h) { height = h; }
12 
13   protected:
14     int width;
15     int height;
16 };
17 
18 class PaintCost {
19   public:
getCost(int area)20     int getCost(int area) { return area * 70; }
21 };
22 
23 class Rectangle : public Shape, public PaintCost {
24   public:
getArea()25     int getArea() { return (width * height); }
26 };
27 
test_inheritance(void)28 int test_inheritance(void)
29 {
30     Rectangle Rect;
31     int       area;
32 
33     Rect.setWidth(5);
34     Rect.setHeight(7);
35 
36     area = Rect.getArea();
37 
38     cout << "Total area: " << Rect.getArea() << endl;
39 
40     cout << "Total paint cost: $" << Rect.getCost(area) << endl;
41 
42     return 0;
43 }
44