Header Ads Widget

Responsive Advertisement

HackerRank problem : Rectangle Area solution in cpp

Q: https://www.hackerrank.com/challenges/rectangle-area/problem


#include <iostream>
using namespace std;
class Rectangle{
  protected: 
  int height;
  int width;
  
  public:
  void display(){
      cout<<width<<"\t"<<height<<endl;
  }
};

class RectangleArea: public Rectangle{
    public:
    void read_input(){
        cin>>width>>height;
    }
    
    void display(){
        cout<<width*height<<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;
} 

Post a Comment

0 Comments