Nearly Similar Rectangles Hackerrank Code Example


Example: Rectangle area hackerrank solution in c++

#include <iostream>  using namespace std; /*  * Create classes Rectangle and RectangleArea  */ class Rectangle{     protected:         int width;         int height;      public:         virtual void display() const{             cout<< width <<' ' << height << endl;         } }; class RectangleArea : public Rectangle {     public:         void display() const override {             cout << (width * height) << endl;         }         void read_input(){             cin >> width >> height;         } };  int main() {     /*      * Declare a RectangleArea object      */     RectangleArea r_area;          /*      * Read the width and height      */     r_area.read_input();          /*      * Print the width and height      */     r_area.Rectangle::display();          /*      * Print the area      */     r_area.display();          return 0; }

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable