-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.cpp
More file actions
56 lines (45 loc) · 1.06 KB
/
Rectangle.cpp
File metadata and controls
56 lines (45 loc) · 1.06 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
#include <iostream>
#include <iomanip>
#include "Rectangle.h"
Rectangle::Rectangle() {
length = 0;
width = 0;
}
Rectangle::Rectangle(double l, double w) {
setDimension(l, w);
}
void Rectangle::setDimension(double l, double w) {
if (l >= 0) {
length = l;
}
else {
length = 0;
}
if (w >= 0) {
width = w;
}
else {
width = 0;
}
}
double Rectangle::getLength() const {
return length;
}
double Rectangle::getWidth() const {
return width;
}
double Rectangle::area() const {
return length * width;
}
double Rectangle::perimeter() const {
return 2 * (length + width);
}
void Rectangle::print() const {
// Output formatting
std::cout << std::fixed << std::showpoint << std::setprecision(2);
const int w = 10;
std::cout << "Length: " << std::setw(w) << length << std::endl;
std::cout << "Width: " << std::setw(w) << width << std::endl;
//std::cout << "Area: " << area() << std::endl;
//std::cout << "Perimeter: " << perimeter() << std::endl;
}