Shape and Measurements

#include<iostream>
using namespace std;
class Shape
{
public:
virtual int getPerimeter() = 0;
};
class Rectangle : public Shape
{
    int length,breadth;
public:
    void in()
    {
    cin>>length>>breadth;
    }
    int getPerimeter()
    {
    return(2*length)+(2*breadth);
    }
};
int main()
{
    Rectangle obj;
  obj.in();
   cout <<"Perimeter of Rectangle is: "<<obj.getPerimeter();
    return 0;
}

14 comments:

  1. change:
    virtual int getPerimeter() = 0;
    };
    class Rectangle : public Shape

    to:
    virtual int getPerimeter()=0;
    };
    class Rectangle:public Shape

    to make it work 100%

    ReplyDelete
  2. #include
    using namespace std;
    class Shape{
    public:
    virtual int getPerimeter()=0;
    };
    class Rectangle:public Shape
    {
    public:
    int getPerimeter()
    { int a,b;
    cin>>a>>b;
    return 2*(a+b);
    }
    };
    int main() {
    Shape *ptr = new Rectangle;
    cout<<"Perimeter of Rectangle is: "<getPerimeter();
    return 0;
    }

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. #include
    using namespace std;
    class Shape {
    public:
    virtual int getPerimeter()=0;
    };

    class Rectangle:public Shape {
    public:
    int getPerimeter() {
    int a,b;
    cin>>a>>b;
    return 2*(a+b);
    }
    };

    int main() {
    Shape *ptr = new Rectangle;
    cout<<"Perimeter of Rectangle is: "<getPerimeter();
    return 0;
    }
    //This Gives 100%

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. For Some reason, Copy Paste is not working properly \_("_")_/
      before getPerimeter(); in main function, add ptr'- >' BUT WITHOUT QUOTES OR SPACES

      Delete
  5. #include
    using namespace std;
    class Shape {
    public:
    virtual int getPerimeter()=0;
    };

    class Rectangle:public Shape {
    public:
    int getPerimeter() {
    int a,b;
    cin>>a>>b;
    return 2*(a+b);
    }
    };

    int main() {
    Shape *ptr = new Rectangle;
    cout<<"Perimeter of Rectangle is: "getPerimeter();
    return 0;
    }

    ReplyDelete
  6. any one plz send 100%working code of this shape and measurement

    ReplyDelete
  7. #include
    using namespace std;
    class Shape {
    public:
    virtual int getPerimeter()=0;
    };

    class Rectangle:public Shape {
    public:
    int getPerimeter()
    {
    int a,b;
    cin>>a>>b;
    return 2*(a+b);
    }
    };

    int main() {
    Shape *ptr = new Rectangle;
    Rectangle r;
    int perimeter;
    perimeter=r.getPerimeter();
    cout<<"Perimeter of Rectangle is: "<<perimeter;
    return 0;
    }

    ReplyDelete