-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScmApp.cpp
More file actions
374 lines (255 loc) · 7.06 KB
/
ScmApp.cpp
File metadata and controls
374 lines (255 loc) · 7.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
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
// Name: Parthkumar Patel Date:August 2nd/2016
#include "Course.h"
#include "ScmApp.h"
#include "ICTCourse.h"
#include "GenEdCourse.h"
#include "Streamable.h"
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
namespace sict{
void ScmApp::pause() const
{
do{
cin.ignore();
cout << '\n' << "Press Enter to continue...";
}while (cin.get() != '\n');
cout << endl;
}
int ScmApp::menu()
{
cout << "Seneca Course Management Tool" << endl
<< "1- List courses." << endl
<< "2- Display the details of a course." << endl
<< "3- Add a course." << endl
<< "4- Change the study load of a course." << endl
<< "5- Load courses from a file." <<endl
<< "6- Save courses to a file." <<endl
<< "0- Exit Program." << endl
<< ">";
int inp;
cin >> inp;
cout << endl;
/*while the proper input is not selected. the user will keep getting prompted until valid input is entered*/
while (inp > 6 || inp < 0)
{
cout << "===Invalid Selection, try again.===";
cin >> inp;
}
return inp;
}
void ScmApp::listCourses() const
{
/*uses forlooop to print out the Courses. It uses i as the index value also the max limit for the course display is
set to either 10 or when noOfCourses reaches its last index*/
cout<< " Row | Code | Course Title | Credits | Study Load | System | Lang. Req. |" << endl;
cout<< "-----|------|-----------------------------------------|---------|------------|---------|-------------|" << endl;
int i=0;
for (i = 0; i < DISPLAY_LINE && i < noOfCourses_; i++)
{
cout<< setw(5) << i ;
courseList_[i]->display(cout);
}
cout << "------------------------------------------------------------------------------------------------------" << endl ;
cout << endl;
}
/*searches through getcourseCode() to find matching coursecode given by the user. if found it returns i, if not then returns -1*/
int ScmApp::searchACourse(const char* courseCode) const
{
int i;
for (i = 0; i < noOfCourses_ ; i++)
{
if(*courseList_[i] == courseCode)
{
return i;
}
}
return -1;
}
void ScmApp::changeStudyLoad(const char* courseCode)
{
int search=0;
/*If searchACourse function returns an index value then the user is prompted input a
studyload value and we use the operator += to modify */
search = searchACourse(courseCode);
if(search != -1)
{
cout << "Please enter the amount of the study load: " ;
int change = 0;
cin >> change;
courseList_[search]->getStudyLoad();
change+= courseList_[search]->getStudyLoad();
courseList_[search]->setStudyLoad(change);
cout << endl;
}else
{
cout << "Not found! \n\n";
}
}
ScmApp::ScmApp(const char* filename)
{
noOfCourses_= 0;
if(filename)
{
strncpy(filename_,filename,256);
}
for(int i=0;i<MAX_NO_RECS;i++)
{
courseList_[i] = nullptr;
}
}
void ScmApp::addACourse(int opt)
{
/*char * courseCd = nullptr;
char courseCds[101];
char courseTl[101];
char* courseTitlep = nullptr;
int credit;
int studyLoadL;
cout << endl << "course code: ";
cin >> courseCds;
courseCd = (char*)courseCds;
cin.ignore();
cout << "Course Title: ";
cin.getline(courseTl, 101);
courseTitlep = (char*)courseTl;
cout << "Course credit: ";
cin >> credit;
cout << "Study Load: ";
cin >> studyLoadL;
*/
if (opt == 1)
{
/*cout << "Computer System: ";
char * compSys = nullptr;
char compSystem[101];
cin >> compSystem;
compSys = (char*)compSystem;
cin.ignore();
courseList_[noOfCourses_] = new ICTCourse(courseCd, courseTitlep,credit,studyLoadL,compSys);
cout << endl;
*/
courseList_[noOfCourses_] = new ICTCourse();
courseList_[noOfCourses_]->read(cin);
}
else if (opt== 2)
{
/*cout << "Language Requirement: ";
int langR;
cin >> langR;
courseList_[noOfCourses_] = new GenEdCourse(courseCd, courseTitlep,credit,studyLoadL,langR);
cout << endl;
*/
courseList_[noOfCourses_] = new GenEdCourse();
courseList_[noOfCourses_]->read(cin);
}
noOfCourses_ += 1;
}
ScmApp::~ScmApp()
{
if(noOfCourses_ > 0)
{
for(int n=0; n < noOfCourses_ ; n++)
{
delete courseList_[n];
}
}
}
ScmApp::ScmApp()
{
for(int i=0; i < MAX_NO_RECS ; i++)
{
delete courseList_[i];
courseList_[i] = nullptr;
}
}
int ScmApp::run()
{
int input;
do{
input= menu();
if(input == 1)
{
listCourses();
}else if(input == 2)
{
}else if(input == 3)
{
int option;
do {
cout << "Please enter the course type (1-ICT or 2-GenEd):";
cin >> option;
}while (option != 1 && option != 2);
addACourse(option);
}
else if (input == 4)
{
cout << endl;
char courseCo[MAX_COURSECODE_LEN + 1];
cout << "Please enter the course code :" ;
cin >> courseCo;
changeStudyLoad(courseCo);
}else if (input == 5)
{
loadRecs();
}else if(input == 6)
{
saveRecs();
}
}while(input != 0);
cout << "Goodbye!!";
return 0;
}
void ScmApp::loadRecs()
{
int readIndex=0;
char ch;
dataFile_.open(filename_,ios::in);
if(dataFile_.fail())
{
dataFile_.clear();
dataFile_.close();
dataFile_.open(filename_,ios::out);
dataFile_.close();
}else
{
for(int i = 0; i < noOfCourses_; i++)
{
delete courseList_[i];
courseList_[i] = nullptr;
}
while(!dataFile_.fail())
{
dataFile_.get(ch);
if(ch == 'I')
{
courseList_[readIndex] = new ICTCourse();
dataFile_.get();
courseList_[readIndex]-> load(dataFile_);
readIndex++;
}else if(ch == 'G')
{
courseList_[readIndex] = new GenEdCourse();
dataFile_.get();
courseList_[readIndex]-> load(dataFile_);
readIndex++;
}
}
noOfCourses_ = readIndex;
dataFile_.close();
}
dataFile_.close();
}
void ScmApp::saveRecs()
{
dataFile_.open(filename_, ios::out);
for(int i = 0; i < noOfCourses_ ; i++)
{
courseList_[i]->store(dataFile_,true);
}
dataFile_.close();
}
};