-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouse-maker.cpp
207 lines (184 loc) · 6.54 KB
/
house-maker.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "house.h"
#include <iostream>
#include <string>
using namespace std;
void makeHouse(House*);
void getHouseDetails(House*);
void setHouseDetails(House*);
// Create a house object with house details derived from client input.
void makeHouse(House* emptyHouse) {
int roomCount;
float length, breadth, height;
string description;
cout << "\n\nSpecify the house details by responding to the following \
prompts:\n" << endl;
cout << "Number of rooms: ";
cin >> roomCount;
cout << "Length (in metres): ";
cin >> length;
cout << "Breadth (in metres): ";
cin >> breadth;
cout << "Height (in metres): ";
cin >> height;
cout << "Description: ";
cin.ignore(256, '\n');
getline(cin, description);
emptyHouse -> setRoomCount(roomCount);
emptyHouse -> setLength(length);
emptyHouse -> setBreadth(breadth);
emptyHouse -> setHeight(height);
emptyHouse -> setDescription(description);
cout << "\n***House Created***" << endl;
cout << "***Returning to home screen***" << endl;
}
// Function to get and display house details requested by client.
void getHouseDetails(House* house) {
int detailToGet;
cout << "\n\nEnter the number corresponding to the detail you want to \
display:\n" << endl;
cout << "1. Number of rooms" << endl;
cout << "2. Length" << endl;
cout << "3. Breadth" << endl;
cout << "4. Height" << endl;
cout << "5. Description" << endl;
cout << "> ";
cin >> detailToGet;
cout << endl;
switch(detailToGet) {
case 1:
cout << "Number of rooms in house: " << house -> \
getRoomCount() << endl;
break;
case 2:
cout << "Length of house: " << house -> getLength() << \
" metre(s)" << endl;
break;
case 3:
cout << "Breadth of house: " << house -> getBreadth() << \
" metre(s)" << endl;
break;
case 4:
cout << "Height of house: " << house -> getHeight() << \
" metre(s)" << endl;
break;
case 5:
cout << "Description for house: " << house -> \
getDescription() << endl;
break;
default:
cout << "*** Invalid option selected ***" << endl;
}
cout << "\n***Returning to home screen***" << endl;
}
// Function to set house details requested by client.
void setHouseDetails(House* house) {
int detailToSet;
cout << "\n\nEnter the number corresponding to the detail you want to \
modify:\n" << endl;
cout << "1. Number of rooms" << endl;
cout << "2. Length" << endl;
cout << "3. Breadth" << endl;
cout << "4. Height" << endl;
cout << "5. Description" << endl;
cout << "> ";
cin >> detailToSet;
cout << "\nEnter new value:" << endl;
cout << "> ";
switch(detailToSet) {
case 1:
{
int oldRoomCount, newRoomCount;
oldRoomCount = house -> getRoomCount();
cin >> newRoomCount;
house -> setRoomCount(newRoomCount);
cout << "Number of rooms in house updated from " << \
oldRoomCount << " to " << newRoomCount << endl;
}
break;
case 2:
{
float oldLength, newLength;
oldLength = house -> getLength();
cin >> newLength;
house -> setLength(newLength);
cout << "Length of house updated from " << oldLength << \
" to " << newLength << endl;
}
break;
case 3:
{
float oldBreadth, newBreadth;
oldBreadth = house -> getBreadth();
cin >> newBreadth;
house -> setBreadth(newBreadth);
cout << "Breadth of house updated from " << oldBreadth << \
" to " << newBreadth << endl;
}
break;
case 4:
{
float oldHeight, newHeight;
oldHeight = house -> getHeight();
cin >> newHeight;
house -> setHeight(newHeight);
cout << "Height of house updated from " << oldHeight << \
" to " << newHeight << endl;
}
break;
case 5:
{
string oldDescription, newDescription;
oldDescription = house -> getDescription();
cin.ignore(256, '\n');
getline(cin, newDescription);
house -> setDescription(newDescription);
cout << "Description of house updated from " << \
oldDescription << " to " << newDescription << endl;
}
break;
default:
cout << "*** Invalid option selected ***" << endl;
}
cout << "\n***Returning to home screen***" << endl;
}
// Main function for client interface, representing the 'home screen menu' of
// the program.
int main() {
int userIntendedTask;
bool houseExists = false;
House house(0, 0, 0, 0, "");
House* housePointer = &house;
cout << "\n\n ==== Welcome to House Maker ==== \n" << endl;
do {
cout << "\nWhat would you like to do:\n\n";
cout << "1. Create a house (Will destroy any house created already)\n";
if (houseExists) {
cout << "2. View some detail of your house\n";
cout << "3. Change the details of your house\n";
}
cout << "4. Close the program and destroy your house\n";
cout << "\nEnter a number corresponding to a task you want to \
perform from the above list" << endl;
cout << "> ";
cin >> userIntendedTask;
switch(userIntendedTask) {
case 1:
makeHouse(housePointer);
houseExists = true;
break;
case 2:
getHouseDetails(housePointer);
break;
case 3:
cout << "You want to modify the house's details" << endl;
setHouseDetails(housePointer);
break;
case 4:
cout << "Closing program" << endl;
break;
default:
cout << "*** Invalid option selected ***" << endl;
}
} while (userIntendedTask != 4);
return 0;
}