-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClasses.cpp
More file actions
57 lines (44 loc) · 1.45 KB
/
Classes.cpp
File metadata and controls
57 lines (44 loc) · 1.45 KB
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
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
double weight; // Weight of box
};
int main() {
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box
Box Box3; // Declare Box3 of type Box
double volume = 0.0; // Store the volume of a box here
double density = 0.0; // Store the density of a box here
// box 1 specification
Box1.height = 5.0;
Box1.length = 6.0;
Box1.breadth = 7.0;
Box1.weight = 120.0;
// box 2 specification
Box2.height = 10.0;
Box2.length = 12.0;
Box2.breadth = 13.0;
Box2.weight = 120.0;
// box 3 specification
Box3.height = 10.0;
Box3.length = 10.0;
Box3.breadth = 10.0;
Box3.weight = 120.0;
// volume of box 1
volume = Box1.height * Box1.length * Box1.breadth;
density = Box1.weight / volume;
cout << "Volume of Box1 : " << volume << " Density : " << density << endl;
// volume of box 2
volume = Box2.height * Box2.length * Box2.breadth;
density = Box2.weight / volume;
cout << "Volume of Box2 : " << volume << " Density : " << density << endl;
// volume of box 3
volume = Box3.height * Box3.length * Box3.breadth;
density = Box3.weight / volume;
cout << "Volume of Box3 : " << volume << " Density : " << density << endl;
return 0;
}