source file name: OOP5.CPP
#include <iostream.h>
// create a class
class Room
{
int len;
int bd;
int ht;
public:
void setdata(int a, int b, int c)
{
len=a;
bd=b;
ht=c;
}
long area() {
return len * bd;
}
long volume() {
return len * bd * ht;
}
};
int main()
{
// create object of Room class
Room room1,room2;
// assign values by function members
room1.setdata(100,25,30);
room2.setdata(300,50,40);
// calculate and display the area and volume of the room 1
cout << "Area of Room 1 = " << room1.area() << endl;
cout << "Volume of Room 1= " << room1.volume() << endl;
// calculate and display the area and volume of the room 1
cout << "Area of Room 2 = " << room2.area() << endl;
cout << "Volume of Room 2= " << room2.volume() << endl;
return 0;
}
output:
0 Comments
Post a Comment