Rectangle Area

Sort by

recency

|

200 Discussions

|

  • + 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<

  • + 1 comment

    Here's my code, pretty simple, easy to understand. The comments will help you :)

    class Rectangle {
        public:
            int width;    // Represents the width of the rectangle
            int height;   // Represents the height of the rectangle
    
            // Virtual function for displaying rectangle properties
            virtual void display() {
                cout << width << " " << height << endl; 
            }
    };
    
    class RectangleArea : public Rectangle { 
        public:
            void read_input() { 
                cin >> width; // Reads the width from the user input
                cin >> height; // Reads the height from the user input
            }
    
            // Overrides the display() method from the base class
            void display() override { 
                cout << width * height << endl; // Displays the area of the rectangle 
            }
    };
    
  • + 0 comments
    class Rectangle{
        public:
        int height,width;
        void display(){
            cout<<width<<" "<<height<<endl;
        }
    };
    class RectangleArea: public Rectangle{
        public:
        void read_input(){
            cin>>width>>height;
        }
        void display(){
            cout<<(width*height);
        }
    };