0% found this document useful (0 votes)
6 views

class & object

The document presents a C++ program that demonstrates the use of classes and objects. It defines a 'Room' class with attributes for length, breadth, and height, along with methods to calculate area and volume. The main function creates an instance of the Room class, assigns values to its attributes, and displays the calculated area and volume.

Uploaded by

Ayush Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

class & object

The document presents a C++ program that demonstrates the use of classes and objects. It defines a 'Room' class with attributes for length, breadth, and height, along with methods to calculate area and volume. The main function creates an instance of the Room class, assigns values to its attributes, and displays the calculated area and volume.

Uploaded by

Ayush Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Program to illustrate the working of

// objects and class in C++ Programming

#include <iostream>

using namespace std;

// create a class

class Room {

public:

double length;

double breadth;

double height;

double calculate_area() {

return length * breadth;

double calculate_volume() {

return length * breadth * height;

};

int main() {

// create object of Room class

Room room1;

// assign values to data members

room1.length = 42.5;

room1.breadth = 30.8;

room1.height = 19.2;

// calculate and display the area and volume of the room

cout << "Area of Room = " << room1.calculate_area() << endl;

cout << "Volume of Room = " << room1.calculate_volume() << endl;

return 0;

}
// Program to illustrate the working of

// objects and class in C++ Programming

#include <iostream>

using namespace std;

// create a class

class Room {

public:

double length;

double breadth;

double height;

double calculate_area() {

return length * breadth;

double calculate_volume() {

return length * breadth * height;

};

int main() {

// create object of Room class

Room room1;

// assign values to data members

room1.length = 42.5;

room1.breadth = 30.8;

room1.height = 19.2;

// calculate and display the area and volume of the room

cout << "Area of Room = " << room1.calculate_area() << endl;

cout << "Volume of Room = " << room1.calculate_volume() << endl;

return 0;

You might also like