Rectangle Area

Sort by

recency

|

202 Discussions

|

  • + 0 comments

    My C++ solution

    #include <iostream>
    
    using namespace std;
    /*
     * Create classes Rectangle and RectangleArea
     */
    class Rectangle{
      protected:
      int width;
      int height;
      
      public:
      Rectangle(){
        width = 0;
        height = 0;
      }
      Rectangle(int _w,int _h) {
         width = _w;
         height = _h;
      }
      void display(){
        std::cout<<width<<" "<<height<<std::endl;
      }
      
      
    };
    
    class RectangleArea: public Rectangle{
            public:
            void read_input(){
                std::cin >> width;
                std::cin >> height;
    
            }
    
            void display(){
                std::cout << width*height<<std::endl;
            }        
    };
    
    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;
    }
    
  • + 0 comments
    #include <iostream>
    
    using namespace std;
    
    class Rectangle
    {
    protected:
        int m_width, m_height;
    
    public:
        virtual void display()
        {
            cout << m_width << " " << m_height << endl;
        }
    };
    
    class RectangleArea : public Rectangle
    {
    
    public:
        void read_input()
        {
            cin >> m_width >> m_height;
        }
        void display() override
        {
            cout << m_width * m_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;
    }
    
  • + 0 comments

    using namespace std; class Rectangle{

    protected:
    int width, height;
    public:
    void display(){
        cout<<width<<" "<<height<<endl;
    }
    

    }; class RectangleArea:public Rectangle { public: void read_input(){ cin>>width>>height; } void display(){ cout<

    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;
    

    }

  • + 0 comments

    Here is Rectangle Area problem solution in C++ - https://programmingoneonone.com/hackerrank-rectangle-area-solution-in-cpp.html

  • + 0 comments

    class Rectangle{ public : int width , height; void read_input(){ cin>>width>>height; } void display(){ cout<