Create a class named 'Rectangle' with two data members 'length' and 'breadth' and two methods to print the area and perimeter of the rectangle respectively. Its constructor having parameters for length and breadth is used to initialize length and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle' class with its constructor having a parameter for its side (suppose s) calling the constructor of its parent class as 'super(s,s)'. Print the area and perimeter of a rectangle and a square.


Create a class named 'Rectangle' with two data members 'length' and 'breadth' and two methods to print the area and perimeter of the rectangle respectively. Its constructor having parameters for length and breadth is used to initialize length and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle' class with its constructor having a parameter for its side (suppose s) calling the constructor of its parent class as 'super(s,s)'. Print the area and perimeter of a rectangle and a square. 




#include <iostream>
using namespace std;
class Rectangle
{
    int l,b;
public:
    Rectangle(int x, int y)
    {
        l=x;
        b=y;
    }

    void area()
    {
        cout<<l*b<< endl;
    }

    void perimeter()
    {
        cout<<2*(l+b)<<endl;
    }
};

class Square:public Rectangle
{
public:
    Square(int z):Rectangle(z,z)
    {}
};

int main()
{
    Rectangle r(3,5);
    Square s(5);
    r.area();
    r.perimeter();
    s.area();
    s.perimeter();
}                  

Create a class named 'Rectangle' with two data members 'length' and 'breadth' and two methods to print the area and perimeter of the rectangle respectively. Its constructor having parameters for length and breadth is used to initialize length and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle' class with its constructor having a parameter for its side (suppose s) calling the constructor of its parent class as 'super(s,s)'. Print the area and perimeter of a rectangle and a square.