Object Oriented Programming Practical 12

Question 1
Write a C++ program to calculate the area and perimeter of rectangles using concept of inheritance.
rectangle.cpp
C
				#include<iostream.h>
#include<conio.h>

class Area
{
   public:
   void area(int x,int y)
   {
      int a=x*y;
   	cout<<"\nArea = "<<a;
   }
};

class Perimeter
{
 	public:
   void perimeter(int x,int y)
   {
		int p=2*(x+y);
      cout<<"\nPerimeter = "<<p;
   }
};

class rectangle:public Area,public Perimeter
{
   int length,breadth;

	public:
   void get_data()
   {
		cout<<"\nEnter length of rectangle: ";
      cin>>length;
      cout<<"\nEnter breadth of rectangle: ";
      cin>>breadth;
   }

   void display()
	{
		cout<<"\nLength of rectangle: "<<length;
		cout<<"\nBreadth of rectangle: "<<breadth;
      area(length,breadth);
      perimeter(length,breadth);
	}
};

void main()
{
	clrscr();
   rectangle r;
   r.get_data();
   r.display();
   getch();
}

			
Output

Leave a Comment

Your email address will not be published. Required fields are marked *