-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.cpp
More file actions
46 lines (38 loc) · 1.03 KB
/
Box.cpp
File metadata and controls
46 lines (38 loc) · 1.03 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
#include <iostream>
#include <iomanip>
#include "Rectangle.h"
#include "Box.h"
Box::Box() {
height = 0;
}
Box::Box(double l, double w, double h) : Rectangle(l, w) {
if (h >= 0)
height = h;
else
height = 0;
}
void Box::setDimension(double l, double w, double h) {
Rectangle::setDimension(l, w);
if (h >= 0)
height = h;
else
height = 0;
}
double Box::getHeight() const {
return height;
}
double Box::calcArea() const {
return 2 * ((Rectangle::getLength() * Rectangle::getWidth() + Rectangle::getLength() * height + Rectangle::getWidth() * height));
}
double Box::calcVolume() const {
return Rectangle::getLength() * Rectangle::getWidth() * height;
}
void Box::print() const {
// Output formatting
std::cout << std::fixed << std::showpoint << std::setprecision(2);
const int w = 10;
Rectangle::print();
std::cout << "Height: " << std::setw(w) << height << std::endl;
std::cout << "Volume: " << std::setw(w) << calcVolume() << std::endl;
std::cout << "Surface Area: " << std::setw(w) << calcArea() << std::endl;
}