-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckIn.h
491 lines (459 loc) · 12.7 KB
/
checkIn.h
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
//header file containing include statements, and namespace statement
#ifndef CHECK_IN
#define CHECK_IN
#include <fstream>
#include <string>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstring>
using namespace std;
class Person
{
public:
Person ()
{
info.resize(1);
}
void assignFirst (string);
void assignLast (string);
void assignEmail (string);
void assignPhone (string);
void assignUser (string);
void assignInfo (string, int);
int countInfo ();
void push ();
void push (int);
string findElement (int);
private:
vector<string> info;
};
using namespace std;
void Person::assignFirst (string fn)
{
info[0] = fn;
}
void Person::assignLast (string ln)
{
info [1] = ln;
}
void Person::assignEmail (string em)
{
info [3] = em;
}
void Person::assignPhone (string ph)
{
info [4] = ph;
}
void Person::assignUser (string us)
{
info [2] = us;
}
void Person::push ()
{
//cout << "Reallocating space for info of size " << info.size() << endl;
info.resize(info.size()+1);
//cout << "Allocated." << endl;
}
void Person:: push (int size)
{
info.resize (size);
}
int Person::countInfo()
{
return info.size();
}
void Person::assignInfo (string pinfo, int position)
{
info[position] = pinfo;
}
string Person::findElement (int index)
{
return info[index];
}
void updateInfo(vector<Person>& v)
{
cin.clear();
cin.ignore(256, '\n');
int choice, index;
string fn, ln, us, em, ph;
bool found = false;
int v_size = v.size();
while (!found)
{
cout << "Enter your First Name (Enter \"Quit\" to got back to main menu) : ";
getline(cin, fn);
if (fn == "Quit")
{
return;
}
cout << "Enter your Last Name: ";
getline(cin, ln);
for (int i = 0; i < v_size; i++)
{
if ((v[i].findElement(0) == fn) && (v[i].findElement(1) == ln))
{
index = i;
found = true;
break;
}
}
if (!found)
{
cout << endl << "ERROR: The combination of the First Name (\"" << fn << "\") and Last Name (\"" << ln << "\") you entered could not be found." << endl;
cout << "Make sure you entered your first name correctly, or register as a \"New\" club member." << endl << endl;
}
}
do
{
do
{
if (cin.fail())
{
cin.clear();
cin.ignore(256, '\n');
}
cout << endl << "What information would you like to update?" << endl << endl;
cout << "\t1\t-\t Username" << endl;
cout << "\t2\t-\t Email (does not change newsletter subscription)" << endl;
cout << "\t3\t-\t Phone Number" << endl;
cout << "\t4\t-\t Exit to main menu" << endl << endl;
cout << "Enter your choice: ";
cin >> choice;
if ((choice < 1) || (choice > 4) || cin.fail())
{
cout << endl << "ERROR: Please enter a valid option." << endl << endl;
}
} while ((choice < 1) || (choice > 4) || cin.fail());
if (choice == 4)
return;
cout << "New " << v[0].findElement(choice + 1) << " for " << v[index].findElement(0) << " " << v[index].findElement(1) << ":\t";
string update;
cin.clear();
cin.ignore(256, '\n');
getline(cin, update);
//cout << "Assigning it to index + 1 : " << choice + 1 << endl;
if (choice == 1) //for username checks to see if username is a duplicate
{
bool identical;
int k = 0;
do
{
identical = false;
if (k != 0)
{
cout << "New " << v[0].findElement(choice + 1) << " for " << v[index].findElement(0) << " " << v[index].findElement(1) << ":\t";
getline(cin, update);
}
int v_size = v.size();
//cout << "3" << endl;
for (int i = 0; i < v_size; i++)
{
string test;
//cout << "1" << endl;
test = v[i].findElement(2);
//cout << "2" << endl;
if (update == test)
{
cout << "ERROR: That username is already taken!" << endl << endl;
identical = true;
break;
}
}
k++;
} while (identical);
}
v[index].assignInfo(update, choice + 1);
} while (choice != 4);
}
void checkInNew (vector<Person>& p, int index)
{
cin.clear();
cin.ignore (256, '\n');
string fn, ln, us, em, ph;
cout << endl << endl << endl << endl;
cout << "Please fill in the following information:" << endl;
cout << "First Name (enter \"Quit\" to exit to main menu): ";
getline (cin, fn);
if (fn == "Quit")
{
return;
}
cout << "Last Name: ";
getline (cin, ln);
bool identical = true;
do
{
cout << "Username (choose a username - case sensitive): ";
cin >> us;
identical = true;
int p_size = p.size ();
//cout << "3" << endl;
for (int i = 0; i < p_size; i++)
{
string test;
//cout << "1" << endl;
test = p[i].findElement(2);
//cout << "2" << endl;
if (us == test)
{
cout << "That username is already taken!" << endl;
identical = false;
break;
}
}
}
while (!identical);
cout << "Email: ";
cin >> em;
cout << "Phone number: ";
cin >> ph;
int v_size = p.size();
p.resize(v_size+1);
p[v_size].push(p[0].countInfo());
p[v_size].assignFirst(fn);
p[v_size].assignLast(ln);
p[v_size].assignUser(us);
p[v_size].assignEmail(em);
p[v_size].assignPhone(ph);
p[v_size].assignInfo("X", index);
cout << string(40, '\n');
cout << "Thank you, " << p[v_size].findElement(0) << "! You're checked in!" << endl;
}
void checkInReturn (vector <Person>& p, int index)
{
bool found;
do
{
cin.clear();
cin.ignore(256, '\n');
string us;
found = false;
cout << "Check-in with your username (case-sensitive) or type \"Quit\" to exit to main menu: ";
cin >> us;
if (us == "Quit")
return;
int p_size = p.size();
//cout << "Your username is:" << us << us<< endl;
for (int i = 0; i < p_size; i++)
{
//cout << "test against: " << p[i].findElement(2) << endl;
if (p[i].findElement(2) == us)
{
p[i].assignInfo("X", index);
cout << string(40, '\n');
cout << "Thank you, " << p[i].findElement(0) << "! You're checked in!" << endl;
found = true;
return;
}
}
if (!found)
{
cout << endl << endl << endl << "ERROR: Username could not be found. Please try again." << endl << endl;
}
} while (!found);
return;
}
void DotSlash ()
{
cout << "**********************************************************************" << endl;
cout << "* ____ ____ ______ ____ ___ ____ *" << endl;
cout << "* || \\\\ || || || || || // \\\\ || || || *" << endl;
cout << "* || || || || || __ ||___ || ||___|| ||___ ||___|| *" << endl;
cout << "* || || || || || |__| || || || || || || || *" << endl;
cout << "* ||__// ||__|| || ____|| ||__ || || ____|| || || *" << endl;
cout << "* *" << endl;
cout << "* C O M P U T E R S C I E N C E *" << endl;
cout << "**********************************************************************" << endl;
cout << endl << endl;
}
bool openFileRead (ifstream& file, const char* fname)
{
file.open (fname);
if (!file)
return false;
else
return true;}
bool openFileWrite (ofstream& file, const char* fname)
{
file.open (fname);
if (!file)
return false;
else
return true;}
// function void studentType () pseudo-clear screen, creates Dot-Slash banner, asks if use is new or returning, depending on selected option, calls the corresponsing function (checkInNew () or checkInReturn ())
//hidden option "Q" to quit the program
//program continues to run until admin types "Q"
void studentType (vector<Person>& v, int index)
{
string choice;
do
{
cout << "\n\n";
cout << "\n\n";
DotSlash ();
cout << endl;
cout << "*****Welcome to Dot - Slash Computer Science Check-In!*****" << endl << endl;
cout << "If you have any questions, feel free to ask one of the ./Officers" << "\n";
cout << "\n\n";
do
{
cout << "Please select an option" << endl << endl;
cout << "\t1 - New member check-in" << endl;
cout << "\t2 - Returning member check-in" << endl;
cout << "\t3 - Returning member update info" << endl;
cout << endl << endl << "Enter \"help\" for more information/help!" << endl << endl << endl;
cout << "What would you like to do? (Using the keyboard, enter the number of the option and press ENTER/RETURN):\t";
cin >> choice;
if (choice != "1"&& choice != "2" && choice != "3" && choice != "Q" && choice != "help")
{
cout << "ERROR: Please enter a valid option (1 or 2)" << endl << endl;
}
}
while (choice != "1" && choice != "2" && choice != "3" && choice != "Q" && choice != "help");
if (choice == "1")
{
checkInNew (v, index);
}
else if (choice == "2")
{
checkInReturn (v, index);
}
else if (choice == "3")
{
updateInfo(v);
}
else if (choice == "help")
{
cout << string(40, '\n');
cout << "HELP MENU:" << endl << endl << endl;
cout << "Please enter the number corresponding to the option of your choice:" << endl << endl << endl;
cout << "\tIf you are a new member, enter '1' on the main menu and then enter your infomation " << endl << endl;
cout << "\tIf you are a returning member, enter '2' on the main menu and then enter your username to check in" << endl << endl;
cout << "\tIf you need to update your information, enter '3' on the main menu and then enter your First Name then Last Name" << endl;
cout << "\tOnce you've entered your name, you will be able to choose an option for whcih info you want to update." << endl << endl << endl;
cout << endl << "\tIf you are a returning member, but haven't used this check-in program before," << endl << "\tyou must first create a username. Please choose option 3, put in your first name," << endl << "\tthen your last name, and then choose to update your username. " << endl;
cout << "\tYou will use this username to check-in. Once you have chosen a " << endl << "\tusername, exit to the main menu, and check in as a returning member." << endl;
cout << endl << endl << endl;
cout << "Press ENTER to continue...";
string cont;
cin.clear();
cin.ignore(256, '\n');
getline(cin, cont);
cout << string(40, '\n');
}
else if (choice == "Q")
{
return;
}
}
while (choice !="Q");
}
// takes information from the file and puts it into the roster vector
void initVector (ifstream& file, vector<Person>& v)
{
file.clear ();
file.seekg (0, ios::beg);
string row;
int pos;
//cout << "Testing first line..." << endl;
getline (file, row);
if (file.fail()) //if the file is blank make the starting titles
{
v[0].push(5);
//cout << "First line none... adding data." << endl;
v[0].assignFirst("First Name");
v[0].assignLast("Last Name");
v[0].assignUser("Username");
v[0].assignEmail("Email Address");
v[0].assignPhone("Phone Number");
return; //exits initVector and returns the value of true to the bool variable
}
else
{
//cout <<"Values in first line valid..." << endl;
file.clear (); //bring pointer to the beginning
file.seekg (0, ios::beg);
int startpos = 0;
pos = 0;
int i = 0;
int j = 0;
getline (file, row);
//cout << "First row taken..." << endl;
while (!file.fail()) //go until file is at the end
{
//cout << "New row..." << endl;
if (i!=0)
{
v.resize(v.size()+1); //since v already has an initialized size of 1, we skip resizing for the first index 0
v[i].push(v[0].countInfo()); //after creating another v element, we must create a vector the same size of the 0 index for the info vector
}
while (pos!=-1) //testing against EOL
{
pos = row.find (',', startpos); //finds "," in the row; returns -1 if EOL
if (pos == -1) //this is for the very last term (after the last ,)
{
v[i].assignInfo(row.substr(startpos), v[i].countInfo()-1);
}
else //
{
//cout << "Finding delim ','" << endl;
string substring;
substring = row.substr (startpos, pos-startpos);
//cout << "Substring: " << substring << endl;
//if (v[i].countInfo()>1)
// v[i].push();
//cout << "info size of v[" << i << "]: " << v[i].countInfo() << endl;
//cout << "debug: countinfo = " << v[i].countInfo() << endl;
/*
if (i==0)
{
v[0].assignInfo(substring, v[0].countInfo()-1);
}
else
{
*/
v[i].assignInfo(substring, j);
//}
startpos = pos + 1;
if (i==0) //for the title element in the roster, creates a new column for it
v[i].push();
j++;
}
}
//cout << "Reallocating vector size..." << endl;
i++;
j=0;
startpos = 0;
getline (file, row);
//cout << "Next row taken..." << endl;
pos = 0;
}
}
return;
}
void exportClose (ofstream& file, vector<Person>& v)
{
int v_size = v.size();
int v_info_size = v[0].countInfo ();
cout << "Exporting data to file..." << endl;
for (int i = 0; i < v_size; i++)
{
if (i!= 0)
{
file << "\n";
}
for (int j = 0; j < v_info_size; j++)
{
if (j!=0)
{
file << ",";
}
file << v[i].findElement(j);
}
}
cout << "Closing file..." << endl;
file.close();
}
#endif