Measure the Area

#include <iostream> 
  using namespace std;
  class Shape

  protected: 
    double x, y; 
  public: 
 
    void set_dim(double i, double j=0)
    { 
      x = i; 
      y = j; 
    } 
    virtual int getArea() = 0;
}; 
       
  class Rectangle : public Shape { 
    public: 
   
      int getArea() {   
        cout <<"Area of Rectangle is:"<< x * y << "\n"; 
       } 
  };   
     
  main(void) 
  { 
    Shape *p; 
    Rectangle r;
    int l,b;
    cin>>l>>b;
    p = &r; 
    p->set_dim(l, b); 
    p->getArea(); 
    return 0; 
  }

8 comments:

  1. #include
    using namespace std;
    class Shape
    {
    protected:
    double x, y;
    public:

    void set_dim(double i, double j=0)
    {
    x = i;
    y = j;
    }
    virtual int getArea()=0;
    };

    class Rectangle:public Shape{
    public:

    int getArea() {
    cout <<"Area of Rectangle is:"<< x * y << "\n";
    }
    };

    main(void)
    {
    Shape *p;
    Rectangle r;
    int l,b;
    cin>>l>>b;
    p = &r;
    p->set_dim(l, b);
    p->getArea();
    return 0;
    }

    ReplyDelete