File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ class Shape
6
+ {
7
+ private:
8
+ int getWidth ();
9
+ int getHeight ();
10
+
11
+ protected:
12
+ int width;
13
+ int height;
14
+
15
+ public:
16
+ Shape () = default ;
17
+ Shape (int , int );
18
+ };
19
+
20
+ int Shape::getWidth () { return width; }
21
+ int Shape::getHeight () { return height; }
22
+ Shape::Shape (int w, int h)
23
+ {
24
+ width = w;
25
+ height = h;
26
+ }
27
+
28
+ class Rectangle : public Shape
29
+ {
30
+ public:
31
+ Rectangle (int w, int h);
32
+ int area ();
33
+ };
34
+
35
+ // this is the way to initialize parent's contructor
36
+ Rectangle::Rectangle (int w, int h) : Shape(w, h) {}
37
+
38
+ int Rectangle::area () { return width * height; }
39
+
40
+ int main ()
41
+ {
42
+ Rectangle r1 (11 , 11 );
43
+ cout << " Area of rectange: " << r1.area () << endl;
44
+ return 1 ;
45
+ }
You can’t perform that action at this time.
0 commit comments