Repository navigation
Expand file tree
/
Copy pathUImanager.cc
More file actions
executable file
·410 lines (315 loc) · 8.95 KB
/
Copy pathUImanager.cc
File metadata and controls
executable file
·410 lines (315 loc) · 8.95 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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <cstdlib>
#include "UImanager.h"
using namespace std;
UImanager::~UImanager()
{
}
void UImanager::mainMenu(int* choice)
{
string str;
*choice = -1;
cout << "\nMembership terms & conditions: " << endl;
cout << " - There are 3 types of memberships, bronze, silver and gold." << endl;
cout << " - If your total purchases reach $100 and above, you will get promoted to silver rank." << endl;
cout << " - If your total purchases reach $300 and above, you will get promoted to gold rank." << endl;
cout << " - NOTE: You are not allowed to rank up twice in one transaction.";
cout << endl << endl << "WELCOME TO THE BOOKSTORE MANAGEMENT SYSTEM" << endl<<endl;
cout << " Course Management:" << endl;
cout << " ( 1 ) Add course" << endl;
cout << " ( 2 ) Delete course" << endl;
cout << " ( 3 ) List all courses" << endl << endl;
cout << " Textbook Management:" << endl;
cout << " ( 4 ) Add textbook" << endl;
cout << " ( 5 ) List course textbooks" << endl << endl;
cout << " Product Management:" << endl;
cout << " ( 6 ) Add product" << endl;
cout << " ( 7 ) Buy a product" << endl;
cout << " ( 8 ) List all products" << endl;
cout << " ( 9 ) View membership status" << endl << endl;
cout << " ( 0 ) Exit" << endl << endl;
while (*choice < 0 || *choice > 9) {
cout << "Enter your selection: ";
*choice = getInt();
}
}
void UImanager::subMenuBuy(int* choice)
{
string str;
*choice = -1;
cout << "\nWhat product do you want to buy?" << endl;
cout << "\n ( 1 ) Book" << endl;
cout << " ( 2 ) Laptop" << endl;
cout << " ( 3 ) Eraser" << endl;
cout << " ( 4 ) Pencil" << endl;
cout << " ( 0 ) Return to main menu" << endl << endl;
while (*choice < 0 || *choice > 4) {
cout << "Enter your selection: ";
*choice = getInt();
}
}
void UImanager::subMenuAdd(int* choice)
{
string str;
*choice = -1;
cout << "\n ( 1 ) Add one course" << endl;
cout << " ( 2 ) Add multiple courses" << endl;
cout << " ( 0 ) Return to main menu" << endl << endl;
while (*choice < 0 || *choice > 2) {
cout << "Enter your selection: ";
*choice = getInt();
}
}
void UImanager::subMenuRemove(int* choice)
{
string str;
*choice = -1;
cout << "\n ( 1 ) Delete one course" << endl;
cout << " ( 2 ) Delete multiple courses" << endl;
cout << " ( 0 ) Return to main menu" << endl << endl;
while (*choice < 0 || *choice > 2) {
cout << "Enter your selection: ";
*choice = getInt();
}
}
void UImanager::subMenuProduct(int* choice)
{
string str;
cout << "\n ( 1 ) Add book" << endl;
cout << " ( 2 ) Add laptop" << endl;
cout << " ( 3 ) Add Eraser" << endl;
cout << " ( 4 ) Add pencil" << endl;
cout << " ( 0 ) Return to main menu" << endl << endl;
while (*choice < 0 || *choice > 4) {
cout << "Enter your selection: ";
*choice = getInt();
}
}
void UImanager::subProductSearch(int* choice)
{
string str;
cout << "\n What product do you want to search for?" << endl;
cout << " ( 1 ) Book" << endl;
cout << " ( 2 ) Laptop" << endl;
cout << " ( 3 ) Eraser" << endl;
cout << " ( 4 ) Pencil" << endl;
cout << " ( 0 ) Return to main menu" << endl << endl;
while (*choice < 0 || *choice > 4) {
cout << "Enter your selection: ";
*choice = getInt();
}
}
bool UImanager::getNumCourse(int& num)
{
string str = "";
cout << endl;
cout << endl << "Enter a number: ";
getline(cin, str);
stringstream ss(str);
ss >> num;
if(num < 0)
{
cout << endl << "Please enter a positive number";
return false;
}
return true;
}
//getCourseData gets info form the user and dynamically allocate the course
//object on the heap
void UImanager::getCourseData(Course** course)
{
string str = "";
string subj, num, name, inst;
int enrol;
cout << endl;
while (str.length() != 8) {
cout << "Enter course code (e.g. COMP2404): ";
getline(cin, str);
}
subj = str.substr(0,4);
num = str.substr(4);
cout << endl << "Enter course name (e.g. Introduction to SE): ";
getline(cin, name);
cout << endl << "Enter instructor name: ";
getline(cin, inst);
cout << endl << "Enter enrolment: ";
getline(cin, str);
stringstream ss(str);
ss >> enrol;
Course *tmpcourse = new Course(subj, num, name, inst, enrol);
(*course) = tmpcourse;
}
//getPencilData gets info form the user and dynamically allocate the pencil
//object on the heap
void UImanager::getPencilData(Pencil** pencil)
{
string str = "";
string leadType, color, brand;
float price;
cout << endl;
cout << endl << "Enter price: ";
getline(cin, str);
stringstream xx(str);
xx >> price;
cout << endl << "Enter brand: ";
getline(cin, brand);
cout << endl << "Enter leadtype (e.g. 2B/2H/HB): ";
getline(cin, leadType);
cout << endl << "Enter color: ";
getline(cin, color);
Pencil *tmppencil = new Pencil(price, brand, leadType, color);
(*pencil) = tmppencil;
}
//getEraserData gets info form the user and dynamically allocate the eraser
//object on the heap
void UImanager::getEraserData(Eraser** eraser)
{
string str = "";
string material, brand, shape;
float price;
cout << endl;
cout << endl << "Enter price: ";
getline(cin, str);
stringstream xx(str);
xx >> price;
cout << endl << "Enter brand: ";
getline(cin, brand);
cout << endl << "Enter material (e.g. rubber/vinyl/synthetic/gum): ";
getline(cin, material);
cout << endl << "Enter shape: ";
getline(cin, shape);
Eraser *tmpEraser = new Eraser(price, brand, material, shape);
(*eraser) = tmpEraser;
}
//getLaptopData gets info form the user and dynamically allocate the laptop
//object on the heap
void UImanager::getLaptopData(Laptop** laptop)
{
string str = "";
string screenSize, brand, hardDriveSize;
float price;
cout << endl;
cout << endl << "Enter price: ";
getline(cin, str);
stringstream xx(str);
xx >> price;
cout << endl << "Enter brand: ";
getline(cin, brand);
cout << endl << "Enter screen size in inch (e.g. 13/15/17): ";
getline(cin, screenSize);
cout << endl << "Enter hard drive size in gigabytes: ";
getline(cin, hardDriveSize);
Laptop *tempLaptop = new Laptop(price, brand, screenSize, hardDriveSize);
(*laptop) = tempLaptop;
}
void UImanager::printCourses(Dlist<Course*> *list)
{
cout << endl << endl << "ALL COURSES:" << endl << endl;
string outStr;
outStr << *list;
cout << outStr << endl;
}
void UImanager::pause()
{
string str;
cout << endl << "\nPress enter to continue...";
getline(cin, str);
}
int UImanager::getInt()
{
string str;
int num;
getline(cin, str);
stringstream ss(str);
ss >> num;
return num;
}
string UImanager::getCourseCode()
{
string str = "";
cout << endl;
while (str.length() != 8) {
cout << "Enter course code (e.g. COMP2404): ";
getline(cin, str);
}
return str;
}
//getBookData gets info form the user and dynamically allocate the book
//object on the heap
void UImanager::getBookData(Book** book)
{
string str = "";
string title, authors, isbn, brand;
int edition, year;
float price;
cout << endl;
cout << endl << "Enter price: ";
getline(cin, str);
stringstream xx(str);
xx >> price;
cout << endl << "Enter brand: ";
getline(cin, brand);
cout << endl << "Enter title: ";
getline(cin, title);
cout << endl << "Enter author name: ";
getline(cin, authors);
cout << endl << "Enter isbn: ";
getline(cin, isbn);
cout << endl << "Enter edition: ";
getline(cin, str);
stringstream ss(str);
ss >> edition;
cout << endl << "Enter year: ";
getline(cin, str);
stringstream ff(str);
ff >> year;
Book *tmpbook = new Book(price, brand, title, authors, isbn, edition, year);
(*book) = tmpbook;
}
void UImanager::cDeletedMessage()
{
cout << endl << "The course is now deleted!" << endl;
}
void UImanager::cAddedMessage()
{
cout << endl << "The course is now added!" << endl;
}
void UImanager::cNotExist()
{
cout << endl << "Course does not exist" << endl;
}
void UImanager::listBooks(Course* course)
{
string bookString;
course->BooksString(bookString);
cout << bookString;
}
void UImanager::coutString(string& output)
{
cout << output;
}
string UImanager::getString(string data, string type){
string str;
cout<< endl << "\nPlease enter the " + data + " of the " + type + " you want:" << endl;
getline(cin, str);
return str;
}
void UImanager::purchased(float& price)
{
string priceStr;
stringstream ss;
ss << price;
priceStr = ss.str();
cout << "\nYou have purchased this product for $" + priceStr + ":" << endl;
}
void UImanager::purchasedFailed()
{
cout << "\nWe couldn't find the product you are looking for" << endl;
}
void UImanager::promoted()
{
cout << "\n\nCongratulations! You have been promoted. (You can check your membership status on the main menu)" << endl;
}