-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.cpp
More file actions
69 lines (55 loc) · 1.05 KB
/
Box.cpp
File metadata and controls
69 lines (55 loc) · 1.05 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
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include "box.h"
Box::Box()
{
length = 0.0;
breadth = 0.0;
height = 0.0;
}
Box::Box(const double newLength, const double newBreadth, const double newHeight)
{
length = newLength;
breadth = newBreadth;
height = newHeight;
}
Box::~Box() {}
double Box::GetVolume()
{
return length * breadth * height;
}
void Box::setLength(double len)
{
length = len;
}
void Box::setBreadth(double bre)
{
breadth = bre;
}
void Box::setHeight(double hei)
{
height = hei;
}
// overload + opp to add two box objects
Box Box::operator+(const Box &b)
{
Box box;
box.length = this->length + b.length;
box.breadth = this->breadth + b.breadth;
box.height = this->height + b.height;
return box;
}
std::ostream &operator<<(std::ostream &os, const Box &box)
{
os << "Length: " << box.length << ", Breadth: " << box.breadth << ", Height: " << box.height;
return os;
}
int main()
{
Box a{2, 5, 6};
Box b;
b.setHeight(2);
b.setBreadth(2);
b.setLength(2);
cout << (a + b) << endl;
return 0;
}