-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog1.cpp
More file actions
47 lines (34 loc) · 1001 Bytes
/
prog1.cpp
File metadata and controls
47 lines (34 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Write a C++ Program to declare a class called Box with private data members
* length, breadth, and height and public memeber functions set_length,
* set_breadth, set_height. Use the concept of pointer to class, compute the
* volume of the two objects using comp_sol function.
*/
#include <iostream>
using namespace std;
class Box {
private:
int length, breadth, height;
public:
void set_length(int length) { this->length = length; }
void set_breadth(int breadth) { this->breadth = breadth; }
void set_height(int height) { this->height = height; }
int comp_sol() { return length * breadth * height; }
};
int main() {
Box b1;
Box *bp1 = &b1;
bp1->set_length(5);
bp1->set_breadth(6);
bp1->set_height(7);
int vol1 = bp1->comp_sol();
Box b2;
bp1 = &b2;
bp1->set_length(5);
bp1->set_breadth(5);
bp1->set_height(5);
int vol2 = bp1->comp_sol();
cout << "Volume of Box 1: " << vol1 << endl;
cout << "Volume of Box 2: " << vol2 << endl;
return 0;
}