//Program : Part B-6
//Create a class Rectangle with length,breadth and area. Create another class Cuboid //that inherits Rectangle and has additional members height and volume. Use single //inheritance property.
//Name : LDK E-NOTES Reg.No. : **********
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class rectangle
{
protected:
int l,b,area;
public:
void getdata()
{
cout<<"Enter the lemgth value : ";
cin>>l;
cout<<"Enter the breadth value : ";
cin>>b;
}
void display()
{
area=l*b;
cout<<"Length = "<<l<<endl;
cout<<"Breadth = "<<b<<endl;
cout<<"Area of rectangle = "<<area<<endl;
}
};
class cuboid:public rectangle
{
private:
int h,vol;
public:
void getdata()
{
rectangle::getdata();
cout<<"Enter the height value : ";
cin>>h;
}
void display()
{
vol=l*b*h;
rectangle::display();
cout<<"Height = "<<h<<endl;
cout<<"Volume of cuboid = "<<vol<<endl;
}
};
void main()
{
cuboid c;
clrscr();
c.getdata();
c.display();
getch();
}
Output 1 :
Enter the lemgth value : 10
Enter the breadth value : 15
Enter the height value : 25
Length = 10
Breadth = 15
Area of rectangle = 150
Height = 25
Volume of cuboid = 3750
Output 2 :
Enter the lemgth value : 15
Enter the breadth value : 6
Enter the height value : 9
Length = 15
Breadth = 6
Area of rectangle = 90
Height = 9
Volume of cuboid = 810
No comments:
Post a Comment