Code TP3 CPP 24 - 25
Code TP3 CPP 24 - 25
class room
{private:
float length, width, height;
public:
// void initdata(float l, float w, float h)
// { cout<<"initialization "<<endl;
// length=l; width=w; height=h;}
room (float l, float w, float h): // This is the constructor
length(l),width(w),height(h)
{cout<<"I am the constructor"<<endl;}
float area()
{cout<<"the area is: "<<length*width<<endl;}
float volume()
{cout<<"the volume is: "<<length*width*height<<endl;}
};
int main()
{ room room1(3,3,3); // working with the constructor
//room1.length=2;room1.width=2;room1.height=2;// direct access to the
// attributes if they were public
// room1.initdata(3,3,3); // working with the initdata method
room1.area();
room1.volume();
return 0;
}