Answer to Question #181612 in C++ for Hauwa ibrahim

Question #181612

Illustrating working of public and private class

Create a class in C++ and name it room. Declare its data members: (length, breadth and height) inside the class as

private

Create a function to initialize the private variables (void getData)

Create two methods/functions called calculateArea (that returns: length * breadth) and calculateVolume (that returns: length * breadth * height ).

Create object of the room class

Pass the values of the private variables as arguments Display the calculated Area of room and Volume of room.

 2


1
Expert's answer
2021-04-15T23:20:56-0400
using namespace std;
class Room
{
	public:
		int length;       
		int breadth; 
                int Height;      
		void setLength( int l );
		void setBreadth( int b );
                void setHeight( int h )
		int getArea();
                int getVolume();
};


/* defining member functions */
void Rectangle::setLength( int l )
{
	length = l;
}
void Rectangle::setBreadth( int b )
{
	breadth = b;
}
void Rectangle::setHeight( int h )
{
	breadth = b;
}
int Rectangle::getArea()
{
	return length * breadth;
}
int Rectangle::getVolume()
{
    return length * breadth*Height;
int main()
{
	int area = rt.getArea();
	cout << "Area : " << area << endl;
	int Volume = rt.getVolume();
	cout << "Volume : " << Volume << end2;
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS