rectangle area hackerrank solution in c 2b 2b

Solutions on MaxInterview for rectangle area hackerrank solution in c 2b 2b by the best coders in the world

showing results for - "rectangle area hackerrank solution in c 2b 2b"
Hanna
03 Jan 2019
1#include <iostream>
2
3using namespace std;
4/*
5 * Create classes Rectangle and RectangleArea
6 */
7class Rectangle{
8    protected:
9        int width;
10        int height;
11
12    public:
13        virtual void display() const{
14            cout<< width <<' ' << height << endl;
15        }
16};
17class RectangleArea : public Rectangle {
18    public:
19        void display() const override {
20            cout << (width * height) << endl;
21        }
22        void read_input(){
23            cin >> width >> height;
24        }
25};
26
27int main()
28{
29    /*
30     * Declare a RectangleArea object
31     */
32    RectangleArea r_area;
33    
34    /*
35     * Read the width and height
36     */
37    r_area.read_input();
38    
39    /*
40     * Print the width and height
41     */
42    r_area.Rectangle::display();
43    
44    /*
45     * Print the area
46     */
47    r_area.display();
48    
49    return 0;
50}