Answer to Question #181609 in C++ for Fatima Muhammad

Question #181609

Illustrating working of class ad objects

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

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

Create object of the room class.

Assign values to the data members declared

Display the calculated Area of room and Volume of room.



1
Expert's answer
2021-04-14T19:07:15-0400
#include <iostream>


using namespace std;


class Room
{
private:
    double length;
    double breadth;
    double height;


public:
    double calculateArea()
    {
        return length*breadth;
    }


    double calculateVolume()
    {
        return length*breadth*length;
    }


    void setLength(double length)
    {
        this->length = length;
    }
    void setBreadth(double breadth)
    {
        this->breadth = breadth;
    }
    void setHeight(double height)
    {
        this->height = height;
    }


    double getLength()
    {
        return length;
    }
    double getBreadth()
    {
        return breadth;
    }
    double getHeight()
    {
        return height;
    }
};


int main()
{
    Room room;
    room.setLength(3);
    room.setBreadth(4);
    room.setHeight(5);


    cout << "length: " << room.getLength() << endl;
    cout << "breadth: " << room.getBreadth() << endl;
    cout << "height: " << room.getHeight() << endl;


    cout << endl << "Area: " << room.calculateArea();
    cout << endl << "Volume: " << room.calculateVolume();


    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