-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHall.cpp
112 lines (88 loc) · 2.76 KB
/
Hall.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Hall.h" // class implemented
using namespace std;
// File scope starts here
/////////////////////////////// PUBLIC ///////////////////////////////////////
//============================= LIFECYCLE ====================================
// Hall Default+Overloaded Constructor
Hall::Hall(float aWidth, float aLength) : mWidth(aWidth), mLength(aLength), mArea(aWidth*aLength) {
this->SetHall(aWidth, aLength);
}
// end Hall constructor
//============================= OPERATORS ====================================
// Stream Insertion
ostream& operator <<(ostream& os, const Hall& r) {
os << endl;
os << "Width = " << r.GetWidth() << endl;
os << "Length = " << r.GetLength() << endl;
os << "Area = " << r.GetArea() << endl << endl;
return os; // enables cout<<Hall1<<Hall2;
}
// end stream insertion
// Stream Extraction
istream & operator >> (istream& in, Hall& r) {
float aWidth, aLength;
cout << endl;
cout << "Width = ";
in >> aWidth; // input Hall Width
cout << "Length = ";
in >> aLength; // input Hall Length
cout << endl;
r.SetHall(aWidth, aLength);
return in; // enables cin>>Hall1>>Hall2;
}
// end stream extraction
//============================= OPERATIONS ===================================
// function that Stores item in the Hall
void Hall::Store() { }
//============================= ACESS ===================================
// function that sets width of Hall
void Hall::SetWidth(float aWidth) {
if (aWidth < 0.0)
cout << "Error: Cannot set a negative width." << endl;
else {
this->mWidth = aWidth;
this->mArea = this->GetWidth()*this->GetLength();
}
}
// end function SetWidth
// function that sets length of Hall
void Hall::SetLength(float aLength) {
if (aLength < 0.0)
cout << "Error: Cannot set a negative length." << endl;
else {
this->mLength = aLength;
this->mArea = this->GetWidth()*this->GetLength();
}
}
// end function SetLength
// function that sets Hall
void Hall::SetHall(float aWidth, float aLength) {
this->SetWidth(aWidth);
this->SetLength(aLength);
}
// end function SetHall
// Overloaded function that sets Hall
void Hall::SetHall(const Hall& aHall) {
this->SetHall(aHall.GetWidth(), aHall.GetLength());
}
// end function SetHall
// function that gets the width of Hall
float Hall::GetWidth() const {
return (this->mWidth);
}
// end function GetWidth
// function that gets the length of Hall
float Hall::GetLength() const {
return (this->mLength);
}
// end function GetLength
// function that gets the Area of Hall
float Hall::GetArea() const {
return (this->mArea);
}
// end function GetArea
// function that gets the Hall
const Hall& Hall::GetHall()const {
return *this;
}
// end function GetHall