-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcs11_ERS_final.cpp
1507 lines (1334 loc) · 41.6 KB
/
cs11_ERS_final.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
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Author: Andrew P
Program: CS11 - 34025 Final Project
Date: May 21, 2010
Descri: menu driven program collects employee data, sorts, calculates, and prints- see README.TXT for further details
*/
//***********************************************************************************************************************************************
// LIBRARIES
//***********************************************************************************************************************************************
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <vector>
#include <ctime>
#include <cctype>
#include <windows.h>
#include <conio.h>
#include <time.h>
using namespace std;
//***********************************************************************************************************************************************
// PROTYPES - DEFINITIONS CAN BE FOUND AT FUNCTIONS
//***********************************************************************************************************************************************
void gotoxy (int,int);
void header ();
void login ();
void accessLog (string, int);
void mainMenu (int&);
void displayMenu (int&);
void searchMenu (int&);
void sortMenu (int&);
double getTax ();
void getFile (ifstream&);
void makeFile (ofstream&);
void readRecords (int&,
vector<string>&,
vector<string>&,
vector<char>&,
vector<int>&,
vector<string>&,
vector<int>&,
vector<double>&,
vector<double>&,
vector<double>&);
void errorLog (string, int);
void dataCheck (int);
void displayRecords (int, vector<string>,
vector<string>,
vector<char>,
vector<int>,
vector<string>,
vector<int>,
vector<double>,
vector<double>,
vector<double>);
void saveRecords (int, vector<string>,
vector<string>,
vector<char>,
vector<int>,
vector<string>,
vector<int>,
vector<double>,
vector<double>,
vector<double>);
int findLowest (const int, const vector<double>);
int findHighest (const int, const vector<double>);
int searchName (const int, const vector<string>);
int searchID (const int, const vector<int>);
void displayResult (int, vector<string>,
vector<string>,
vector<char>,
vector<int>,
vector<string>,
vector<int>,
vector<double>,
vector<double>,
vector<double>);
void sortLast (int,
vector<string>&,
vector<string>&,
vector<char>&,
vector<int>&,
vector<string>&,
vector<int>&,
vector<double>&,
vector<double>&,
vector<double>&);
void sortID (int, vector<string>&,
vector<string>&,
vector<char>&,
vector<int>&,
vector<string>&,
vector<int>&,
vector<double>&,
vector<double>&,
vector<double>&);
void findTotals (const int, const vector<double>, const vector<double>);
void goodBye ();
//***********************************************************************************************************************************************
// MAIN - PRIMARY CONTROL THRU MENUS
//***********************************************************************************************************************************************
int main()
{
//***********************************************************************************************************************************************
// Variables
//***********************************************************************************************************************************************
//vector length and highlight
int size = int();
int index = int();
//records
vector<string> fName(size);
vector<string> lName(size);
vector<char> initial(size);
vector<int> employeeID(size);
vector<string> state(size);
vector<int> zip(size);
vector<double> hours(size);
vector<double> rate(size);
vector<double> net(size);
//menu selection
int select = int();
int display = int();
int search = int();
int sort = int();
//***********************************************************************************************************************************************
// Begin Function
//***********************************************************************************************************************************************
header(); //DISPLAYS PROGRAM NAME
gotoxy(25,22);
cout << "Please view README.txt located in program directory\n\n";
//ADD DISPLAY README OPTION
login(); //RUN LOGIN WITH ENCRIPTION
while (true) //THIS LOOP KEEPS YOU IN MAIN MENU
{
mainMenu(select); //TO MAIN MENU DISPLAY
if (select == 1) //OPTION IMPORT FILES
{
readRecords(size, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else if (select == 2) //OPTION DISPLAY RECORDS
{
while (true)
{
displayMenu(display);
if (display == 1)
{
index = findLowest(size, net);
displayResult(index, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else if (display == 2)
{
index = findHighest(size, net);
displayResult(index, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else if (display == 3)
{
findTotals(size, hours, net);
}
else if (display == 4)
{
displayRecords(size, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else if (display == 5)
{
break;
}
else
{
goodBye();
}
}
}
else if (select == 3) //OPTION SEARCH RECORDS
{
while (true)
{
searchMenu(search);
if (search == 1)
{
index = searchName(size, lName);
displayResult(index, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else if (search == 2)
{
index = searchID(size, employeeID);
displayResult(index, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else if (search == 3)
{
break;
}
else
{
goodBye();
}
}
}
else if (select == 4) //OPTION SORT RECORDS
{
while (true)
{
sortMenu(sort);
if (sort == 1)
{
sortLast(size, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else if (sort == 2)
{
sortID(size, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else if (sort == 3)
{
break;
}
else
{
goodBye();
}
}
}
else if (select == 5) //OPTION PRINT/SAVE RECORDS
{
saveRecords(size, fName, lName, initial, employeeID, state, zip, hours, rate, net);
}
else //EXIT PROGRAM
{
goodBye();
}
}
return 0;
}
//***********************************************************************************************************************************************
// FUNCTIONS - SEE DEFINITIONS
//***********************************************************************************************************************************************
//
//
//***********************************************************************************************************************************************
// GOTOXY - ALLOWS CURSOR OUT MANIPULATION
//***********************************************************************************************************************************************
void gotoxy (int x,int y)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { x, y };
SetConsoleCursorPosition( hStdout, position );
}
//***********************************************************************************************************************************************
// HEADER - DISPLAYS PROGRAM NAME FOR INSTITUTION, HEADS LOGIN SCREEN
//***********************************************************************************************************************************************
void header ()
{
cout << "\t\t\t**********************************\n"
<< "\t\t\t* Employee Record System (ERS) *\n"
<< "\t\t\t* Long Beach City College LBCC *\n"
<< "\t\t\t* 4901 East Carson Street *\n"
<< "\t\t\t* Long Beach, CA 90808 *\n"
<< "\t\t\t**********************************\n"
<< endl;
}
///***********************************************************************************************************************************************
// LOGIN - READS USER DIRECTORY, DECRYPTS PASSWORDS, ALLOWS/DENIES USER ACCESS TO MENUS
//***********************************************************************************************************************************************
void login ()
{
int list = int();
int y = 9;
char dummy[9];
char match[9];
string fileword = string();
string userName = string();
vector<string> users;
vector<string> admit;
string mark = string();
bool flag = true;
bool loop = true;
bool hit = false;
int counter = int();
ifstream privy;
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
privy.open("G:\\ERS\\userDir.txt");
//privy.open("C:\\Users\\Alias\\Desktop\\CS_11\\Final\\userDir.txt");
while(!privy.eof())
do
{
privy >> userName;
if (privy.eof() || privy.fail())
{
loop = false;
}
else
{
users.push_back(userName);
}
privy >> fileword;
if (privy.eof() || privy.fail())
{
privy.clear();
privy.ignore(1000, '\n');
loop = false;
}
else
{
admit.push_back(fileword);
list++;
}
}
while (loop);
privy.close();
while(counter<3 && flag == true )
{
char password[9];
userName.clear();
SetConsoleTextAttribute(hConsole, 6);//gold
gotoxy(25, 10); cout << "User Name: ";
gotoxy(25, 11); cout << " --------- ";
gotoxy(25, 12); cout << "| |";
gotoxy(25, 13); cout << " --------- ";
gotoxy(45, 10); cout << "Password: ";
gotoxy(45, 11); cout << " --------- ";
gotoxy(45, 12); cout << "| |";
gotoxy(45, 13); cout << " --------- ";
gotoxy(26, 12);
cin >> userName;
for (int i= 0; i<list; ++i)
{
if(userName == users[i])
{
strcpy_s(match, admit[i].c_str());
y = strlen(match);
gotoxy(46, 12);
for (int j=0; j < y; j++)
{
password[j] = _getch();
password[j] = password[j] + 99 + j;
cout << '*';
}
password[y] = '\0';
hit = true;
}
}
if(!hit)
{
gotoxy(46, 12);
for (int j=0; j < 3; j++)
{
dummy[j] = _getch();
cout << '*';
}
}
if (strcmp(password, match)==0)
{
mark = userName + " succesfully logged in ";
errorLog(mark, counter);
accessLog(mark, counter);
SetConsoleTextAttribute(hConsole, 10);//green
gotoxy(25, 14); cout << "Login successful... " << endl;
gotoxy(25, 15); cout << " " << endl;
gotoxy(25, 16); system("pause");
flag = false;
}
else
{
SetConsoleTextAttribute(hConsole, 14);//yellow
if (counter == 1)SetConsoleTextAttribute(hConsole, 12);//red
if (counter == 2)SetConsoleTextAttribute(hConsole, 4);//dark red
gotoxy(25, 14); cout << "Invalid User-Name or password" << endl;
gotoxy(25, 15); cout << "Try entering the information again" << endl;
gotoxy(25, 16); cout << ++counter << " of 3 attempts remaining!" << endl;
}
}
if (flag == true)
{
mark = userName + " was denied access to the ERS ";
errorLog(mark, counter);
SetConsoleTextAttribute(hConsole, 12);//red
cout << "\nPermission to access the system denied!" << endl;
cout << "Please see your administrator for user-name and password help." << endl;
cout << "\n\nProgram will terminate!" << endl;
exit(1);
}
}
//***********************************************************************************************************************************************
// ACCESS LOG - RECORDS ACCESS PERMISSIONS AND USE
//***********************************************************************************************************************************************
void accessLog (string access, int index)
{
ofstream printaccess;
time_t currentTime;
time(¤tTime);
//extern string user;
printaccess.open("G:\\ERS\\logs\\accessLog.txt",ios::app);
//printaccess.open("C:\\Users\\Alias\\Desktop\\CS_11\\Final\\logs\\accessLog.txt",ios::app);
printaccess << asctime(localtime(¤tTime)) << "\t" << " - " << access << index+1 << endl;
printaccess.close();
}
//***********************************************************************************************************************************************
// MAIN MENU - BASE PROGRAM OPTIONS MENU
//***********************************************************************************************************************************************
void mainMenu (int& select)
{
system("cls");
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 7);//default
cout << "\n\t\t M A I N M E N U\t- Description"
<< "\n\t\t===================\n";
SetConsoleTextAttribute(hConsole, 6);//gold
cout << "\n\t\t 1. IMPORT\t\t- loads file to be processed";
SetConsoleTextAttribute(hConsole, 9);//blue
cout << "\n\t\t 2. DISPLAY\t\t- shows records from import file";
SetConsoleTextAttribute(hConsole, 10);//green
cout << "\n\t\t 3. SEARCH\t\t- searches records per user";
SetConsoleTextAttribute(hConsole, 11);//aqua
cout << "\n\t\t 4. SORT\t\t- sorts records per user";
SetConsoleTextAttribute(hConsole, 13);//pink
cout << "\n\t\t 5. PRINT\t\t- prints file to user's desktop";
SetConsoleTextAttribute(hConsole, 14);//yellow
cout << "\n\t\t 6. EXIT\t\t- exits program";
SetConsoleTextAttribute(hConsole, 7);
cout << "\n\t\t-------------------"
<< endl;
cout << "\n\n\tPlease enter your selection: ";
cin >> select;
if (cin.fail()) //then quit
{
cin.clear();
cin.ignore(1000, '\n');
select = 6; //force quit
}
}
//***********************************************************************************************************************************************
// DISPLAY MENU - OPTIONS MENU TO DISPLAY RECORDS
//***********************************************************************************************************************************************
void displayMenu (int& display)
{
system("cls");
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
cout << "\n\t\t D I S P L A Y "
<< "\n\t\t===================\n";
SetConsoleTextAttribute(hConsole, 9);
cout << "\n\t\t 1. LOWEST SALARY"
<< "\n\t\t 2. HIGHEST SALARY"
<< "\n\t\t 3. TOTAL HOURS & INCOME"
<< "\n\t\t 4. ALL RECORDS"
<< "\n\t\t 5. RETURN to MAIN MENU"
<< "\n\t\t 6. EXIT";
SetConsoleTextAttribute(hConsole, 7);
cout << "\n\t\t-------------------"
<< endl;
cout << "\n\n\tPlease enter your selection: ";
cin >> display;
if (cin.fail()) //then quit
{
cin.clear();
cin.ignore(1000, '\n');
display = 5; //force quit
}
}
//***********************************************************************************************************************************************
// SEARCH MENU - OPTIONS MENU TO SEARCH RECORDS
//***********************************************************************************************************************************************
void searchMenu (int& search)
{
system("cls");
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
cout << "\n\t\t S E A R C H "
<< "\n\t\t===================\n";
SetConsoleTextAttribute(hConsole, 10);
cout << "\n\t\t 1. by LAST NAME"
<< "\n\t\t 2. by ID"
<< "\n\t\t 3. RETURN to MAIN MENU"
<< "\n\t\t 4. EXIT";
SetConsoleTextAttribute(hConsole, 7);
cout << "\n\t\t-------------------"
<< endl;
cout << "\n\n\tPlease enter your selection: ";
cin >> search;
if (cin.fail()) //then quit
{
cin.clear();
cin.ignore(1000, '\n');
search = 3; //force quit
}
}
//***********************************************************************************************************************************************
// SORT MENU - OPTIONS MENU TO SORT RECORDS
//***********************************************************************************************************************************************
void sortMenu (int& sort)
{
system("cls");
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
cout << "\n\t\t S O R T "
<< "\n\t\t===================\n";
SetConsoleTextAttribute(hConsole, 11);
cout << "\n\t\t 1. by LAST NAME"
<< "\n\t\t 2. by ID"
<< "\n\t\t 3. RETURN to MAIN MENU"
<< "\n\t\t 4. EXIT";
SetConsoleTextAttribute(hConsole, 7);
cout << "\n\t\t-------------------"
<< endl;
cout << "\n\n\tPlease enter your selection: ";
cin >> sort;
if (cin.fail()) //then quit
{
cin.clear();
cin.ignore(1000, '\n');
sort = 3; //force quit
}
}
//***********************************************************************************************************************************************
// GET TAX - LOAD TAX RATE PER DOCUMENT
//***********************************************************************************************************************************************
double getTax()
{
double tax = double();
string mark = string();
ifstream getTax;
getTax.open("G:\\ERS\\tax.txt");
//getTax.open("C:\\Users\\Alias\\Desktop\\CS_11\\Final\\tax.txt");
if (!getTax) //if no file then goes to the failed state
{
cout << "\nTax file does not exist or is not located in corresponding directory" << endl;
getTax.clear();
mark = " Missing TAX document. ";
errorLog(mark, -1);
tax = 0;
}
else
{
getTax.peek();
if(getTax.eof())
{
cout << "\nTax file is EMPTY, tax will not be deducted from net pay." << endl;
tax = 0;
mark = "Tax document empty file ";
errorLog(mark, -1);
}
else
{
getTax >> tax;
if (getTax.fail() || tax >= 100 || tax < 0)
{
cout << "\nTax data is CORRUPT, tax will not be deducted from net pay. " << endl;
getTax.clear();
tax = 0;
mark = " Tax DATA fail! ";
errorLog(mark, -1);
}
tax = tax/100;
}
}
getTax.close();
return tax;
}
//***********************************************************************************************************************************************
// GET FILE - FILE REQUEST FOR READ RECORDS
//***********************************************************************************************************************************************
void getFile (ifstream& fin)
{
string fileName = string();
bool error = false;
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
do
{
SetConsoleTextAttribute(hConsole, 7);
cout << "\nEnter input filename: ";
cin >> fileName;
//CHANGE DIRECTORY
fileName = "G:\\ERS\\" + fileName + ".txt";
//fileName = "C:\\Users\\Alias\\Desktop\\" + fileName + ".txt";
fin.open(fileName.c_str());
if (!fin)
{
SetConsoleTextAttribute(hConsole, 12);
system("cls");
errorLog("Attempt to open " + fileName + " FAIL ", 80);
cout << "Cannot Open the input file.\nPlease try again..." << endl;
fin.clear();
error = true;
}
else
{
SetConsoleTextAttribute(hConsole, 10);
cout << "\nFANTASTIC! Your file was found.\n\n" << fileName << endl;
SetConsoleTextAttribute(hConsole, 7);
accessLog(fileName, 0);
error = false;
}
}
while(error);
}
void makeFile (ofstream& fout)
{
string fileName = string();
cout << "\nEnter input filename: ";
cin >> fileName;
//CHANGE DIRECTORY
fileName = "G:\\ERS\\print\\" + fileName + ".txt";
//fileName = "C:\\Users\\Alias\\Desktop\\CS_11\\Final\\print\\" + fileName + ".txt";
fout.open(fileName.c_str());
}
//***********************************************************************************************************************************************
// READ RECORDS - LOADS RECORDS FROM TXT (see - GET FILE) INTO VECTORS FOR PROCESSING
//***********************************************************************************************************************************************
void readRecords (int& size,
vector<string>& fname,
vector<string>& lname,
vector<char>& initial,
vector<int>& employeeID,
vector<string>& state,
vector<int>& zip,
vector<double>& hours,
vector<double>& rate,
vector<double>& net)
{
string mark = string(); //error marks
ifstream in;
bool flag = bool();
bool error = bool();
bool loop = bool();
double tax = double();
int errorCount = int();
int counter = int();
string name; //string input
char mi = char(); //char input
int num = int(); //int input
double val = double(); //double input
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
tax = getTax(); //loads tax value from document
getFile(in);
in.peek();
if (!in) //if no file then goes to the failed state
{
cout << "File does not exist" << endl;
in.clear();
mark = "Open attempt on non-existing file";
errorLog(mark, -1);
}
else if(in.eof())
{
cout << "File is empty" << endl;
mark = "Open attempt on empty file";
errorLog(mark, -1);
}
else
{
while(!flag)
{
error = false; //reset error flag
//get first name
do
{
in >> name;
if (in.fail())
{
mark = "first name input FAIL - line : ";
errorLog(mark, size);
in.clear();
in.ignore(1, ' ');
loop = true;
error = true;
}
else
loop = false;
}
while (loop);
name[0] = toupper(name[0]); //ensure capitalized
fname.push_back(name);
//get last name
do
{
in >> name;
if (in.fail())
{
mark = "last name input FAIL - line : ";
errorLog(mark, size);
in.clear();
in.ignore(1, ' ');
loop = true;
error = true;
}
else
loop = false;
}
while (loop);
name[0] = toupper(name[0]); //ensure capitalized
lname.push_back(name);
//get middle initial
do
{
in >> mi;
if (in.fail())
{
mark = "middle initial input FAIL - line : ";
errorLog(mark, size);
in.clear();
in.ignore(1, ' ');
loop = true;
error = true;
}
else
loop = false;
}
while (loop);
mi = toupper(mi); //ensure capitalized
initial.push_back(mi);
//get employee ID
do
{
in >> num;
if (in.fail())
{
mark = "employee ID input FAIL - line : ";
errorLog(mark, size);
in.clear();
in.ignore(1, ' ');
loop = true;
error = true;
}
else
loop = false;
}
while (loop);
employeeID.push_back(num);
//get state
do
{
in >> name;
if (in.fail())
{
mark = "state input FAIL - line : ";
errorLog(mark, size);
in.clear();
in.ignore(1, ' ');
loop = true;
error = true;
}
else
loop = false;
}
while (loop);
for(unsigned int i=0;i<name.length();i++)
{
name[i] = toupper(name[i]); //ALL CAPS for STATE
}
state.push_back(name);
//get ZIP
do
{
in >> num;
if (in.fail())
{
mark = "Zipcode input FAIL - line : ";
errorLog(mark, size);
in.clear();
in.ignore(1, ' ');
loop = true;
error = true;
}
else
loop = false;
}
while (loop);
zip.push_back(num);
//get hours worked
do
{
in >> val;
if (in.fail())
{
mark = "hours worked input FAIL - line : ";
errorLog(mark, size);
in.clear();
in.ignore(1, ' ');
loop = true;
error = true;
}
else
loop = false;
}
while (loop);
hours.push_back(val);
//get payrate
do
{
in >> val;
if (in.fail())
{
mark = "pay rate input FAIL - line : ";
errorLog(mark, size);
in.clear();
in.ignore(1, ' ');
loop = true;
error = true;
}
else
loop = false;
}
while (loop);
rate.push_back(val);
net.push_back(rate[size]*hours[size]-(rate[size]*hours[size]*tax));
size++;
counter++;
if (error)
{
errorCount++;
}
in.peek();
if (in.eof())
{
flag = true;
}
}//exit loop
}//end else
dataCheck(counter);
SetConsoleTextAttribute(hConsole, 12);
cout << endl << errorCount << " records contain bad data!" << endl;
SetConsoleTextAttribute(hConsole, 7);
system("pause");
in.close();
}
//***********************************************************************************************************************************************
// ERROR LOG - RECORDS PROGRAM ERRORS WHILE IN USE
//***********************************************************************************************************************************************
void errorLog (string error, int index)
{
ofstream printerror;
time_t currentTime;
time(¤tTime);
printerror.open("G:\\ERS\\logs\\errorLog.txt",ios::app);
//printerror.open("C:\\Users\\Alias\\Desktop\\CS_11\\Final\\logs\\errorLog.txt",ios::app);
printerror << asctime(localtime(¤tTime)) << "\t - " << error << index+1 << endl;
printerror.close();
}
//***********************************************************************************************************************************************
// DATA CHECK - REQUEST RECORD LIMIT
//***********************************************************************************************************************************************
void dataCheck (int qty)
{
int desired = 30;
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
cout << "\nPlease Enter the expectant # of RECORDS [default = 30] : ";
cin >> desired;
if (cin.fail())
{
cin.clear();
cin.ignore(1000, '\n');
}
if (qty > desired)
{
SetConsoleTextAttribute(hConsole, 12);
cout << endl << "# of Records read exceeds expectant by " << qty - desired << endl << endl;
SetConsoleTextAttribute(hConsole, 7);
errorLog("# of Records read exceeds expectant by ", qty - desired- 1);
}
else if (qty < desired)
{
SetConsoleTextAttribute(hConsole, 12);
cout << endl << "# of Records read does not meet expectant by " << desired - qty << endl << endl;
SetConsoleTextAttribute(hConsole, 7);
errorLog("# of Records read short expectant by ", desired - qty - 1);
}
else
{
SetConsoleTextAttribute(hConsole, 10);
cout << endl << "# of Records meet expectant. Data check PASSED. " << endl << endl;
SetConsoleTextAttribute(hConsole, 7);
}
accessLog("# of Records imported: ", qty);
}
//***********************************************************************************************************************************************
// DISPLAY RECORDS - SCREEN OUTPUT OF ALL RECORDS OPTION 4 (see - DISPLAY MENU)
//***********************************************************************************************************************************************
void displayRecords (int size,