-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.cpp
More file actions
974 lines (764 loc) · 29.1 KB
/
admin.cpp
File metadata and controls
974 lines (764 loc) · 29.1 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
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
/////////////////////////////// *{ WHOLE ADMIN CLASS DEFINED HERE. }* ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "header.h"
//*FUNCTION TO ENCRYPT OR DECRYPT USING [XOR_CIPHER].*//
string Xor_Cipher(const string& text, const string& key){
string result = text;
for(int i=0 ; i<text.size() ; i++){
result[i] = text[i] ^ key[i % key.size()]; //MASKING WITH THE ^ {size of key}.
}
return result;
}
//CONSTRUCTOR FOR THE ADMIN CLASS...
Admin::Admin(string name , string password ){
this->name = name;
this->password = password;
}
//*DESTRUCTOR FOR THE ADMIN CLASS.*//
Admin::~Admin(){
}
//*I-STREAM FRIEND FUNCTION TO TAKE INPUT.*//
istream& operator >> (istream& in_put , Admin& obj){
cout<<"\n ENTER THE ADMIN NAME : ";
in_put>>obj.name;
cout<<"\n ENTER THE ADMIN PASSWORD : ";
in_put>>obj.password;
return in_put;
}
//*VERIFICATION FUNCTION.*//
bool Admin::LOGIN_VERIFY(){
string compare_1;
string compare_2;
cout<<"\n ENTER THE ADMIN NAME : ";
cin>>this->name;
cout<<"\n ENTER THE ADMIN PASSWORD : ";
cin>>this->password;
string decrypted_name = Xor_Cipher(this->name , "key");
string decrypted_password = Xor_Cipher(this->password , "key");
ifstream pass("admin_pass.txt" , ios::in ); //OPEN FILE IN READING MODE...
if(!pass){
cout<<"\n FILE NOT FOUND...";
return false;
}
while(!pass.eof() ){
pass>>compare_1>>compare_2;
if( compare_1 == decrypted_name && compare_2== decrypted_password ){
pass.close();
return true;
}
}
pass.close(); // CLOSING THE FILE...
return false; // GRANTING ACCESS...
}
//*UNALLOATION OF MEMORY.*//
void Admin::Free_Memory(char** Product_Name , double* Price , double* Total_Price , int* Quantity , int row){
for(int i=0 ; i<row ; i++){
delete [] Product_Name[i]; // DELETING THE MEMORY ALLOCATED IN HEAP.
}
delete [] Product_Name;
delete [] Total_Price;
delete [] Quantity;
delete [] Price;
Product_Name = NULL; // UNDANGLING THE ARRAYS.
Total_Price = NULL;
Quantity = NULL;
Price = NULL;
}
//*A KIND OF MAIN FOR ADMIN.*//
void Admin::MAIN_MENU()
{
char choice;
char exit;
do{
cout<< "\n\t\t-----------------------------------";
cout<< "\n\t\t| >> WELCOME TO ADMIN MENU << |";
cout<< "\n\t\t-----------------------------------\n\n";
//loading_line(); // CALLING THE LOADING LINE FUNCTION.
cout<<"\t\t -"<<setfill('-')<<setw(57)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(55)<<left<<"<< ENTER THE CORRESPOMDING CHARACTER TO PROCEED >> "<<"|\n";
cout<<"\t\t | "<<setfill('-')<<setw(55)<<""<<setfill(' ')<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"A. CAFE STOCK MANAGEMENT "<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"B. GENERATE NOTIFICATION ( If item lower in quantity )"<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"C. ORDER ITEM [ IF LOWER IN QUANTITY ] "<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"D. SEARCH, ADD, REMOVE & UPDATE ANY ITEM IN STOCK"<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"E. ADD OR REMOVE CREDENTIALS OF EMPLOYEE OR STAFF."<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"F. DISPLAY INTERESTING NOTIFICATIONS"<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"G. SEE ONLINE ORDERS "<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"H. HANDLE COMPLAINTS "<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"I. BEST-SELLER EMPLOYES"<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"J. TRACK THE SALES RECORD. [ AT ONE-STOP ] "<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"K. PLAY GAMES [* AMUSEMENT *]. "<<"|\n";
cout<<"\t\t | "<<setw(55)<<left<<"L. LOGOUT FROM THE SITE "<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(57)<<"-"<<setfill(' ')<<endl;
cin>>choice;
switch (choice)
{
case 'A':
case 'a': // [ 1 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
this->stock_management();
}
break;
case 'B':
case 'b': // [ 2 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
int read;
cout<<"\n\t\t-------------------------------------------------------";
cout<<"\n\t\t| >> THIS FUNCTION WAS TO GENERATE NOTIFICATIONS. << |";
cout<<"\n\t\t| >> WHEN PRODUCT LOW IN QUANTITY. << |";
cout<<"\n\t\t| >> NOW IT IS AUTOMATED - PRESS [1] TO READ FILE << |";
cout<<"\n\t\t-------------------------------------------------------\n\n";
cin>>read;
if(read == 1){
this->Read_Notifications();
//Sleep(5000);
}
else{
break;
}
}
break;
case 'C':
case 'c': // [ 3 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
cout<<"\n LINKING WITH INVENTORY MANAGEMENT-[UPDATE-ITEM] "<<endl;
this->Update_Item();
}
break;
case 'D':
case 'd': // [ 4 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
this->inventory_management();
}
break;
case 'E':
case 'e': // [ 5 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
this->Change_Credentials();
}
break;
case 'F':
case 'f': // [ 6 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
this->Notification_Hub();
}
break;
case 'G':
case 'g': // [ 7 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
this->see_details_of_online_orders();
this->Give_Response_To_Order();
}
break;
case 'H':
case 'h': // [ 8 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
this->Response_to_Complaints();
}
break;
case 'I':
case 'i': // [ 9 ]
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
this->Sales_Handling_Hub();
}
break;
case 'J': // [10]
case 'j':
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
t1.track_sales();
}
break;
case 'K': // [11]
case 'k':
{
clearScreen(); // CALLING THE CLEAR SCREEN FUNCTION.
Play_Games();
}
break;
case 'L':
case 'l': // [ 12 ]
{
cout<<"\t\t -"<<setfill('-')<<setw(50)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(48)<<left<<" ** TERMINATING THE PROGRAM ** "<<"|\n";
cout<<"\t\t | "<<setw(48)<<left<<" && THANKS FOR COMING && "<<"|\n";
cout<<"\t\t | "<<setw(48)<<left<<" GOOD_BYE"<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(50)<<"-"<<setfill(' ')<<endl<<endl;
return;
}
default:
{
cout<<"\n\t\t--------------------------------------\n";
cout<<"\t\t| !!!! ENTER A VALID INPUT !!!! |\n";
cout<<"\t\t----------------------------------------\n";
break;
}
}
}while(1);
return;
}
/////////////// [* STOCK HANDLING *] /////////////////////
void Admin::stock_management()
{
char w;
cout<<"\n *** [ WELCOME TO THE STOCK MANAGEMENT MENU ] *** \n\n";
cout<<" WHAT OPERATION DO YOU WANT TO PERFORM ? \n";
cout<<"\t ENTER >> \n\t [1]. TO SEE THE STOCK. \n\t [2]. TO HANDLE STOCK AT ONE PLACE. \n\t [0]. EXIT. \n\n";
cin>>w;
switch(w)
{
case '1':
{
this->display_stock(); //*calling the display stock function.*//
break;
}
case '2':
{
this->inventory_management(); //*calling the management function.*//4
break;
}
case '0':
{
cout<<"\n *** [ EXITING FROM THE STOCK MANAGEMENT MENU ] *** \n";
break;
}
default:
{
cout<<"\n\t\t--------------------------------------\n";
cout<<"\t\t| !!!! ENTER A VALID CHOICE !!!! |\n";
cout<<"\t\t----------------------------------------\n";
this->stock_management();
}
}
}
////////////// [ COMPLAIN FEEDBACK FUNCTION ] ///////////////////
void Admin::Response_to_Complaints()
{
cin.ignore();
char c;
cout<<"\n\t\t-------------------------------------------------------------------\n";
cout<<"\t\t| >>> WELCOME TO THE REVIEW SECTION <<< |\n";
cout<<"\t\t| >>> YOU CAN SEE AND RESPOND THE CUSTOMERS REVIEWS FROM HERE. <<< |\n";
cout<<"\t\t| >>> DO YOU WANT TO GIVE RESPOSE TO THE REVIEWS <?> <<< |\n";
cout<<"\t\t| >>> YES [Y/y] or NO TO EXIT [N/n] <<< |\n";
cout<<"\t\t---------------------------------------------------------------------\n";
cin>>c;
if(c=='y' || c=='Y')
{
const int s=200;
char reaD[s];
ifstream read("review.txt",ios::in); // READING THE REVIEWS BY THE USERS.
while(read.getline(reaD,s,'\n')){
cout<<reaD<<endl;
}
read.close(); // CLOSING FILE TO PREVENT CORRUPTION.
const int size = 200 , a = 10 ;
char res[size];
char name[a];
cin.ignore();
cout<<"\n ENTER THE USER NAME OR ID HERE >>> \n";
cin.getline(name, a );
cout<<"\n ENTER YOUR RESPONSE >>> \n"; // GIVING RESPONSE TO THE USERS REVIEWS.
cin.getline(res, size);
ofstream t("response.txt", ios::app);
if( !t ){
cout<<"\n FILE NOT FOUND. \n";
}
else{
t<<" RESPONDING TO [ "<<name<<" ] :: "<<res<<endl;
t.close(); // CLOSING FILE TO PREVENT CORRUPTION.
}
}
else if(c=='n' || c=='N'){
return;
}
return;
}
///////// [* GENERATE NOTIFICATION ' NOTIFICATION HANDLING ' *] ////////////
void Admin::Notification_Hub()
{
const int maxLines = 150;
const int size = 300;
char chat[maxLines][size];
int line = 0;
int key;
int choice;
buttons(); // CALLING THE BUTTONS FUNCTION.
while(1){
cout<<"\t\t -"<<setfill('-')<<setw(32)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(30)<<left<<" [ WHAT DO YOU WANT TO DO ? ] "<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(32)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(30)<<left<<" 1. ADD NOTIFICATIONS. "<<"|\n";
cout<<"\t\t | "<<setw(30)<<left<<" 2. VIEW NOTIFICATIONS. "<<"|\n";
cout<<"\t\t | "<<setw(30)<<left<<" 3. REMOVE NOTIFICATIONS. "<<"|\n";
cout<<"\t\t | "<<setw(30)<<left<<" 4. EXIT {RETURN BACK} "<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(32)<<"-"<<setfill(' ')<<endl;
cin>>choice;
switch(choice)
{
case 1: /////// [ ADD ] ///////
{
cout<<"\nENTER THE NOTIFICATION >>>>\n";
fstream o("notification.txt", ios::app); // OPENING FILE IN APPEND MODE.
cin.ignore();
cin.getline(chat[line], size);
o<< chat[line] <<endl; // SAVING DATA IN FILE.
o.close(); // CLOSING FILE TO PREVENT CORRUPTION.
break;
}
case 2: ////////// [ VIEW ] ////////////
{
ifstream d("notification.txt"); // IT IS READING AND DISPLAYING DATA AT THE SAME TIME.
line=0;
while(line < maxLines && d.getline(chat[line], size)){
cout<<" [ "<< line+1 <<" ] "<<chat[line] <<endl;
line++;
}
break;
}
case 3: ////////// [ DELETE ] /////////
{
ifstream e("notification.txt");
line = 0;
while(e.getline(chat[line], size) && line < maxLines){ // READING AND DISPLAYING FILE AT-ONCE
cout<<" [ "<<line+1<<" ] "<<chat[line] <<endl;
line++;
}
cout<<"\nENTER THE NOTIFICATION *{INDEX}* YOU WANT TO REMOVE: >>>\n";
cin>>key;
if(key >= 1 && key <= line){
key -- ; // Adjust key to array index [0].
ofstream w("notification.txt", ios::out);
for(int i = 0; i < line; i++){
if(i!= key){ // SKIP THE SPECIFIC LINE WHILE WRITING BACK...
w<< chat[i]<<endl;
}
}
w.close(); // CLOSING FILE TO PREVENT CORRUPTION.
}
else{
cout<<"\nINVALID INDEX.\n";
}
break;
}
case 4:
{
cout<<"\n\t\t-----------------------------------------------";
cout<<"\n\t\t| !EXITING THE NOTIFICATION HANDLING MENU! |";
cout<<"\n\t\t-----------------------------------------------\n\n";
return;
}
default:
{
cout<<"\n\t\t--------------------------------------\n";
cout<<"\t\t| !!!! ENTER A VALID INPUT !!!! |\n";
cout<<"\t\t----------------------------------------\n";
this->Notification_Hub(); // CALLING THE FUNCTION AGAIN.
break;
}
}
}
}
///////// *[ SEE ONLINE ORDERS ]* ////////////
void Admin::see_details_of_online_orders()
{
cout<<"\n\t\t----------------------------------------------------------\n";
cout<<"\t\t| **** [ WELCOME TO THE ONLINE ORDER MENU ] **** |\n";
cout<<"\t\t| [ SEE THE DETAILS OF ORDERS PLACED BY THE CUSTOMERS ] |\n";
cout<<"\t\t------------------------------------------------------------\n";
int count=0;
char ch;
fstream read("online.txt" , ios::in);
if(read.is_open())
{
while(!read.eof()){
read.get(ch);
if(ch == '\n'){
count++;
}
}
}
else{
cerr<<"\n FILE NOT FOUND. \n";
return;
}
read.close();
string display[count+3];
int i=0;
fstream read1("online.txt" , ios::in);
while(!read1.eof()){
getline(read1, display[i]);
cout<<display[i]<<"\n"; //*DISPLAY DATA.*//
i++;
}
read1.close();
cout<<"\n\t\t-------------------------------------------------------\n";
cout<<"\t\t| ** [ SO THAT WERE ALL WITH THE ONLINE ORDERS. ] ** |\n";
cout<<"\t\t| <<<< GOOD BYE >>>> |\n";
cout<<"\t\t---------------------------------------------------------\n";
return;
}
///////// *[ RESPONSE TO ORDER. ]* ////////////
void Admin::Give_Response_To_Order()
{
const int s = 300 , n = 50 ;
char* rev = new char[s]; // ALLOCATING MEMORY IN THE HEAP.
string name;
string user_name;
cout<<"\n\t\t-----------------------------------------------------------\n";
cout<<"\t\t| GIVE RESPONSE TO THE CUSTOMER [STUDENT-STAFF] FROM HERE. |\n";
cout<<"\t\t-------------------------------------------------------------\n";
cin.ignore();
name = this->name;
cout<<" ENTER THE CUSTOMER NAME [ **** ] >>> :: ";
getline(cin , user_name);
cout<<" ENTER YOUR RESPONSE >> \n";
cin.getline(rev , s );
ofstream write("responseOrder.txt" , ios::app ); // WRITING IN APPEND MODE TO AVOID TRUNKING.
if(!write){
cout<<"\n ERROR OPENING FILE \n";
cout<<" CHECK THE FILE NAME \n";
}
else{
write<<"RESPONDED BY :: [ "<<name<<" ] TO { "<<user_name<<" } "<<rev<<endl;
}
write.close(); // CLOSING FILE TO PREVENT CORRUPTION.
delete []rev;
rev = NULL;
return;
}
//*MAIN SALES HANDLING FUNCTION.*//
void Admin::Sales_Handling_Hub(){
int choice;
cout<<"\t\t -"<<setfill('-')<<setw(40)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(38)<<left<<" >>> [ SELECT TO OVERVIEW ] <<< "<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(40)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(38)<<left<<" [1]. EMP. INDIVIDUAL SALES. "<<"|\n";
cout<<"\t\t | "<<setw(38)<<left<<" [2]. BEST SELLING ITEM. "<<"|\n";
cout<<"\t\t | "<<setw(38)<<left<<" [3]. BEST SELLER EMPLOYEE."<<"|\n";
cout<<"\t\t | "<<setw(38)<<left<<" [4]. EXIT."<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(40)<<"-"<<setfill(' ')<<endl;
cin>>choice;
switch(choice){
case 1:
{
this->see_individual_sales();
break;
}
case 2:
{
this->see_best_selling_item();
break;
}
case 3:
{
this->see_best_seller_employee();
break;
}
case 4:
{
cout<<"\n\t\t----------------------";
cout<<"\n\t\t| >>> [EXITED] <<< |";
cout<<"\n\t\t----------------------\n";
return;
}
default:
{
cout<<"\n\t\t--------------------------------------\n";
cout<<"\t\t| !!!! ENTER A VALID INPUT !!!! |\n";
cout<<"\t\t----------------------------------------\n";
this->Sales_Handling_Hub();
}
}
return;
}
///// [* TRACK INDIVIDUAL SALES *] ///////
void Admin::see_individual_sales()
{
char yes;
int ID;
cout<<"\n\t\t----------------------------------------------------------\n";
cout<<"\t\t| >>> YOU CAN SEE THE BEST SELLER EMPLOYEE FROM HERE <<< |\n";
cout<<"\t\t------------------------------------------------------------\n";
buttons(); // CALLING THE BUTTONS FUNCTION.
cout<<"\t\t -"<<setfill('-')<<setw(32)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(30)<<left<<" >>> [ SELECT THE ID ] <<< "<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(32)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(30)<<left<<" [1]. EMPLOYEE_1 "<<"|\n";
cout<<"\t\t | "<<setw(30)<<left<<" [2]. EMPLOYEE_2 "<<"|\n";
cout<<"\t\t | "<<setw(30)<<left<<" [3]. EMPLOYEE_3 "<<"|\n";
cout<<"\t\t | "<<setw(30)<<left<<" [4]. EMPLOYEE_4 "<<"|\n";
cout<<"\t\t | "<<setw(30)<<left<<" [5]. EMPLOYEE_5 "<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(32)<<"-"<<setfill(' ')<<endl;
cout<<"\n\t ENTER THE EMPLOYEE-ID TO TRACK SALES RECORD [ 1-5 ] >>> :: \n";
cin>>ID;
loading_line(); // CALLING THE LOADING LINE FUNCTION.
string file_name;
switch(ID){
case 1:
{
file_name = "emp1.txt";
break;
}
case 2:
{
file_name = "emp2.txt";
break;
}
case 3:
{
file_name = "emp3.txt";
break;
}
case 4:
{
file_name = "emp4.txt";
break;
}
case 5:
{
file_name = "emp5.txt";
break;
}
default:
{
cout<<"\n\t\t--------------------------------------\n";
cout<<"\t\t| !!!! ENTER A VALID INPUT !!!! |\n";
cout<<"\t\t----------------------------------------\n";
see_individual_sales();
}
}
const int col=20;
int row=0;
char a;
fstream line(file_name, ios::in); // OPEN FILE IN READING MODE.
if(!line){
cerr<<"\n\t\t FILE NOT FOUND. CHECK THE FILE NAME.\n";
return;
}
while(line.get(a)){
if(a=='\n'){ // COUNTING THE NUMBER OF LINES FROM THE FILE.
row++ ;
}
}
line.clear(); // CLEARING THE BUFFER SPACE.
line.seekg( 0 , ios::beg); // MOVE CURSOR TO THE BEGINING OF FILE.
line.close(); // CLOSING THE FILE TO PREVENT DATA CORRUPTION.
////////////////////////////////////////////////
char** Product_Name = new char*[this->row];
for(int i=0 ; i<this->row ; i++){
Product_Name[i] = new char[col]; // ALLOCATING MEMORY IN THE HEAP.
}
int* Price = new int[this->row];
double* Total_Price = new double[this->row];
int* Quantity = new int[this->row];
double sum = 0;
int w=0;
ifstream q( file_name , ios::in ); // READING FROM FILE.
if(!q){
cout<<" FILE NOT FOUND ! \n";
}
int R=0;
cout<<"\n\t\t------------------------------------------------\n";
cout<<"\t\t| TOTAL SALES MADE BY EMPLOYEE ["<<ID<<"] >>>> ARE = |\n";
cout<<"\t\t------------------------------------------------\n";
cout<<"\t ORDER "<<" PRODUCT_NAME "<<" PRICE "<<" QUANTITY "<<" TOTAL_PRICE"<<endl<<endl;
while( !q.eof() ){
q>>Product_Name[R] >>Price[R] >>Quantity[R] >>Total_Price[R] ;
if( !q.eof() ){ // DISPLAYING CONTENT OF FILE.
cout<<setw(5)<<"\t [ "<<R+1<<" ] "<<setw(5)<<" "<<setw(10)<<Product_Name[R]<<" | "<<setw(5)<<Price[R]<<" | "<<setw(5)<<Quantity[R]<<" | "
<<setw(5)<<Total_Price[R]<<endl ;
R++;
}
}
q.close(); // CLOSING FILE TO AVOID CORRUPTION.
for( ; w<R ; w++ ){
sum += Total_Price[w] ; // CALCULATING THE TOTAL SALE SUM.
}
cout<<"\n\n\t\t -"<<setfill('-')<<setw(42)<<"-"<<setfill(' ')<<endl;
cout<<"\t\t | "<<setw(25)<<left<<" NO. OF ORDERS >> "<<" :: "<<setw(8)<<w<<"|\n";
cout<<"\t\t | "<<setw(25)<<left<<" TOTAL BILLINGS >> "<<" :: "<<setw(8)<<sum<<"|\n";
cout<<"\t\t -"<<setfill('-')<<setw(42)<<"-"<<setfill(' ')<<endl;
for(int i=0 ; i<row ; i++){
delete [] Product_Name[i]; // DELETING THE MEMORY ALLOCATED IN HEAP.
}
delete [] Product_Name;
delete [] Total_Price;
delete [] Quantity;
delete [] Price;
Product_Name = NULL; // UNDANGLING THE ARRAYS.
Total_Price = NULL;
Quantity = NULL;
Price = NULL;
cout<<"\n\t\t---------------------------------------------\n";
cout<<"\t\t| DO YOU WANT TO SEE OTHER'S EMPLOYEE SALES ? |\n";
cout<<"\t\t| PROCEES WITH [Y/Y] AND RETURN WITH [N/n] |\n";
cout<<"\t\t-----------------------------------------------\n";
cin>>yes;
if(yes=='y' || yes=='Y'){
see_individual_sales();
}
else{
return;
}
return;
}
///// [* SEE THE BEST SELLER EMPLOYEE *] ///////
void Admin::see_best_seller_employee() {
const int col = 20;
int row = 0, R = 0;
char a;
double Highest_Sale = 0;
int Item_Count = 0;
int Save_Id = 0;
for(int i=0 ; i<5 ; i++){
string file_name = "emp" + to_string(i + 1) + ".txt";
fstream line(file_name, ios::in);
if (!line) {
cerr << "\n\t\t FILE NOT FOUND. CHECK THE FILE NAME.\n";
return;
}
while (line.get(a)) {
if (a == '\n') {
row++;
}
}
line.clear();
line.seekg(0, ios::beg);
line.close();
int order_count = 0;
double sale = 0;
char** Product_Name = new char*[row];
for (int i = 0; i < row; i++) {
Product_Name[i] = new char[col];
}
double* Price = new double[row];
double* Total_Price = new double[row];
int* Quantity = new int[row];
ifstream q(file_name, ios::in);
if(!q){
cout<<" FILE NOT FOUND ! \n";
}
while(q >> Product_Name[R] >> Price[R] >> Quantity[R] >> Total_Price[R]) {
sale += Total_Price[R];
order_count += Quantity[R];
R++;
}
q.close();
if (sale > Highest_Sale) {
Highest_Sale = sale;
Item_Count = order_count;
Save_Id = i + 1;
}
for (int i = 0; i < row; i++) {
delete[] Product_Name[i];
}
delete[] Product_Name;
delete[] Price;
delete[] Total_Price;
delete[] Quantity;
}
cout << "\n\n\t\t -" << setfill('-') << setw(42) << "-" << setfill(' ') << endl;
cout << "\t\t | " << setw(25) << left << " EMPLOYEE >> " << " :: " << setw(8) << Save_Id << "|\n";
cout << "\t\t | " << setw(25) << left << " NO. OF ORDERS >> " << " :: " << setw(8) << Item_Count << "|\n";
cout << "\t\t | " << setw(25) << left << " TOTAL BILLINGS >> " << " :: " << setw(8) << Highest_Sale << "|\n";
cout << "\t\t -" << setfill('-') << setw(42) << "-" << setfill(' ') << endl;
cout << "\n\t\t---------------------------------------------\n";
cout << "\t\t| DO YOU WANT TO SEE OTHER'S EMPLOYEE SALES ? |\n";
cout << "\t\t| PROCEED WITH [Y/y] AND RETURN WITH [N/n] |\n";
cout << "\t\t-----------------------------------------------\n";
cin >> a;
if (a == 'y' || a == 'Y') {
this->see_individual_sales();
} else {
return;
}
}
///// [* SEE THE BEST SELLING PRODUCT *] ///////
void Admin::see_best_selling_item(){
const int col = 20;
int row=0 , R=0;
char a;
fstream line("sales.txt", ios::in); // OPEN FILE IN READING MODE.
if(!line){
cerr<<"\n\t\t FILE NOT FOUND. CHECK THE FILE NAME.\n";
return;
}
while(line.get(a)){
if(a == '\n'){
row++;
}
}
line.clear(); //CLEAR THE BUFFER SPACE.
line.seekg(0, ios::beg); //MOVE CURSOR TO THE BEGINING OF FILE.
line.close(); //CLOSE THE FILE TO PREVENT CORRUPTION.
////////////////////////////////////////////
string* Product_Name = new string[row];
double* Total_Price = new double[row];
int* Quantity = new int[row];
ifstream read("sales.txt", ios::in);
if(!read){
cout << " FILE NOT FOUND ! \n";
return;
}
string product;
double price, total, sale = 0;
int quantity;
while(read >> product >> price >> quantity >> total){
sale += total; //CALCULATE TOTAL SALES.
bool found = false;
for(int i=0 ; i<R ; i++){
if(Product_Name[i] == product){ // finding the common product...
Total_Price[i] += total;
Quantity[i] += quantity;
found = true;
break;
}
}
if(!found){ //FEEDING ARRAYS ONLY UNIQUE PRODUCTS...
Product_Name[R] = product;
Total_Price[R] = total;
Quantity[R] = quantity;
R++;
}
}
read.close();
int Highest_Quantity = 0;
string Best_Product;
for(int i=0 ; i<R ; i++){
if(Quantity[i] > Highest_Quantity){
Highest_Quantity = Quantity[i];
Best_Product = Product_Name[i];
}
}
cout << "\n\t\t -" << setfill('-') << setw(43) << "-" << setfill(' ') << endl;
cout << "\t\t | " << setw(25) << left << " BEST SELLING PRODUCT >> " << " :: " << setw(8) << Best_Product << "|\n";
cout << "\t\t | " << setw(25) << left << " QUANTITY SOLD >> " << " :: " << setw(8) << Highest_Quantity << "|\n";
cout << "\t\t -" << setfill('-') << setw(43) << "-" << setfill(' ') << endl;
delete []Quantity; //unallocating the memory.
delete []Total_Price;
delete []Product_Name;
Quantity = NULL;
Total_Price = NULL;
Product_Name = NULL;
int mans;
cout<<"\n WOULD YOU LIKE TO INCREASE IT'S QUANTITY<?>";
cout<<"\n [1]. YES OR [2]. NO. ";
cin>>mans;
if(mans==1){
this->Update_Item();
}
else{
return;
}
return;
}