-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·301 lines (264 loc) · 6.67 KB
/
main.cpp
File metadata and controls
executable file
·301 lines (264 loc) · 6.67 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
//main.cpp
//Max Smiley
//CS202 - program 2
//this main function acts as a client of my materials classes and data structures.
//its purpose is to demonstrate how all the functions in these classes work.
//I would have liked to add functionality to read/write from a file, so a persistent
//list could be maintained, but ran out of time.
//most of the i/o for the program is done in Main, with the exception of specific display
//functions and, glaringly, the Exercise_Set::edit() function, which takes user input to
//add/remove/complete different elements of the circular linked list contained therein.
//in hindsight, i should have implemented that functionality here in main, with a dynamic cast,
//but I had already coded it and ran out of time.
//keep in mind, input is very weakly guarded. A char input into an int will cause an infinite loop.
//I planned on fixing this as well, but I focused more on cleaning up numerous segmentation
//faults and memory leaks.
#include "materials.h"
#include "list.h"
using namespace std;
void getUserInput(Materials & materials);
void modifyList(Materials & materials);
int main()
{
Materials materials;
getUserInput(materials);
modifyList(materials);
materials.display();
cout << "Thank you for using my list manager!\n\n";
return 0;
}
void modifyList(Materials & materials)
{
char chinput = 'x';
int input = -1;
while (input != 0)
{
cout << "\nWould you like to add more material, or modify?\n";
cout << "M: Modify.\n";
cout << "A: Add.\n";
cout << "Q: Quit. \n";
cin >> chinput;
cin.ignore(100, '\n');
cout << "\n\n";
chinput = toupper(chinput);
switch(chinput)
{
case 'Q':
input = 0;
break;
case 'A':
getUserInput(materials);
break;
case 'M':
{
while(chinput != 'Q')
{
cout << "Which material would you like to modify? (enter '0' to quit) ";
cin >> input;
cin.ignore(100, '\n');
while(input <= 0 || input > materials.getSize())
{
if(input == 0)
{
break;;
}
cout << "\nINVALID INPUT, TRY AGAIN! ";
cin >> input;
cin.ignore(100, '\n');
}
if(input == 0)
{
break;
}
cout << "\n\nOkay, element #" << input << ", what would you like to do?\n";
cout << "E: EDIT\n";
cout << "R: REMOVE\n";
cout << "C: COMPLETE\n";
cout << "Q: QUIT\n";
cout << "CHOICE: ";
cin >> chinput;
cin.ignore(100, '\n');
cout << "\n\n";
chinput = toupper(chinput);
switch(chinput)
{
case 'Q':
cout << "Done modifying. \n\n";
break;
case 'R':
materials.remove(input);
break;
case 'E':
materials.edit(input);
break;
case 'C':
materials.complete(input);
break;
}
materials.display();
input = -1;
}
}
}
}
}
void getUserInput(Materials & materials)
{
int arrlength = 256;
char input = 'e';
while(input != 'Q')
{
cout << "\nAdding a material. Which type of material to add?\n";
cout << "R: Reading.\n";
cout << "E: Excercise set.\n";
cout << "L: Lecture.\n";
cout << "Q: Quit adding.\n";
cout << "CHOICE: ";
cin >> input;
cin.ignore(100, '\n');
cout << "\n";
input = toupper(input);
switch(input)
{
case 'Q':
cout << "Done adding. \n\n";
break;
case 'R':
{
char * name = new char[arrlength];
char * author = new char[arrlength];
int chapter, page;
cout << "Adding reading.\n";
cout << "What is the name of the reading material? ";
cin.getline(name, arrlength);
cout << "\nWhat is the name of the author? ";
cin.getline(author, arrlength);
cout << "\nWhat is the chapter number? ";
cin >> chapter;
cin.ignore(100, '\n');
cout << "\nWhat is the page number? ";
cin >> page;
cin.ignore(100, '\n');
Reading * r = new Reading(name, author, chapter, page);
materials.add(*r);
delete[] name;
delete[] author;
break;
}
case 'E':
{
char * setname = new char[arrlength];
int length;
cout << "Adding an exercise set.\n";
cout << "What is the name of the set? ";
cin.getline(setname, arrlength);
cout << "\nWhat is the length of the set? ";
cin >> length;
cin.ignore(100, '\n');
cout << "\n\n";
Exercise_Set * ex = new Exercise_Set(setname);
for(int i = 1; i <= length; ++i)
{
char * exname = new char[arrlength];
cout << "What is question #" << i << "? ";
cin.getline(exname, arrlength);
Exercise * e = new Exercise(exname);
ex->add(e);
delete[] exname;
}
materials.add(*ex);
delete[] setname;
break;
}
case 'L':
{
char * name = new char[arrlength];
char * presenter = new char[arrlength];
const char * medium;
int numSlides;
char ch = 'x';
cout << "Adding lecture.\n";
cout << "What is the title of the lecture? ";
cin.getline(name, arrlength);
cout << "\nWho will be presenting the lecture? ";
cin.getline(presenter, arrlength);
cout << "\nWill the lecture be presented";
cout << "\n(O)nline, or in (C)lass? ";
cin >> ch;
cin.ignore(100, '\n');
ch = toupper(ch);
//need ways to remove elements, and complete elements:
/*
void modifyList(Materials & materials)
{
char chinput = 'x';
int input = -1;
while (input != 0)
{
while(chinput != 'Q')
{
cout << "Lets change some materials. What is the index\n";
cout << "of the list element you'd like to modify?\n";
cout << "enter '0' to exit this loop. ";
cin >> input;
cin.ignore(100, '\n');
if(input == 0)
{
break;
}
while(input < 0 || input > materials.getSize())
{
cout << "\nINVALID INPUT, TRY AGAIN! ";
cin >> input;
cin.ignore(100, '\n');
}
cout << "\n\nOkay, element #" << input << ", what would you like to do?\n";
cout << "E: EDIT\n";
cout << "R: REMOVE\n";
cout << "Q: QUIT\n";
cout << "CHOICE: ";
cin >> chinput;
cin.ignore(100, '\n');
cout << "\n\n";
chinput = toupper(chinput);
switch(chinput)
{
case 'Q':
cout << "Done modifying. \n\n";
break;
case 'R':
materials.remove(input);
break;
case 'E':
materials.edit(input);
break;
}
}
}
materials.display();
}
*/
switch(ch)
{
case 'O':
medium = "online";
break;
case 'C':
medium = "class";
break;
default:
medium = "unspecified";
break;
}
cout << "\nHow many slides in the lecture? ";
cin >> numSlides;
cin.ignore(100, '\n');
Lecture * l = new Lecture(name, presenter, medium, numSlides);
materials.add(*l);
delete[] name;
delete[] presenter;
}
}
}
materials.display();
}