-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperMarket-POS-System.cpp
2061 lines (1750 loc) · 51.9 KB
/
SuperMarket-POS-System.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
#include<iostream>
#include"Interface.h"
#include<fstream>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<ctime>
#include<dos.h>
using namespace std;
class Exception_handling{
static int tot_exceptions;
public:
template<class Number>
static bool checkcreditno(Number numc){ //checking the number of digits for creditcard
int digits;
try{
while(numc!= 0){
numc = numc/10;
digits+= 1;
}
if(digits == 16)
return true;
else{
string str = "Exception occurred!";
tot_exceptions+= 1;
throw str;
}
}
catch(string str){
cout<< endl<< str<< endl<< "Re-Enter the CreditCard Number: ";
return false;
}
}
static long long formnum(char cell[12]){ //convert an array to a number
long long num = 0;
int cnt = 0;
long long val = 0;
int dig = 0, mult = 1;
while(cell[cnt]!= '\0'){
dig+= 1;
cnt++;
}
cnt = (dig-1);
while(cnt != -1){
val = cell[cnt] - 48;
num = num + (val * mult);
mult*= 10;
cnt--;
}
return num;
}
static int formid(char ID[10]){ //convert an array to a number ie. ID
int id = 0;
int cnt = 0;
int val = 0;
int dig = 0, mult = 1;
while(ID[cnt]!= '\0'){
dig+= 1;
cnt++;
}
cnt = (dig-1);
while(cnt != -1){
val = ID[cnt] - 48;
id = id + (val * mult);
mult*= 10;
cnt--;
}
return id;
}
static bool checkid(const char ID[10]){ //function to check whether the id contains any invalid char or not
int flag = 0, cnt = 0;
try{
while(cnt != 10){
if( ID[cnt]!= '\0' ){
if( (ID[cnt]>47) && (ID[cnt]<58) ){}
else
throw ID[cnt];
}
cnt++;
}
return true;
}
catch(const char exception){
tot_exceptions+= 1;
cout<< endl<< "EXCEPTION OCCURRED!"<< endl<< "You're not supposed to Enter data consist of character(s), like: "<< exception<< endl;
cout<< "RE-ENTER ID: "<< endl;
return false;
}
}
static bool checkcontact(const char cont[12]){ //function to check whether the cell number contains any invalid char or not
int flag = 0, cnt = 0;
try{
while(cnt != 12){
if( cont[cnt]!= '\0' ){
if( (cont[cnt]>47) && (cont[cnt]<58) ){}
else
throw cont[cnt];
}
cnt++;
}
return true;
}
catch(const char exception){
tot_exceptions+= 1;
cout<< endl<< "EXCEPTION OCCURRED!"<< endl<< "You're not supposed to Enter data consist of character(s), like: "<< exception<< endl;
cout<< "RE-ENTER Mobile Number: "<< endl;
return false;
}
}
static bool checkcashiername(const char name[50]){ //function to check the entered name for exception handling.
int cnt = 0, cnt2 = 0;
int fg = 0;
int len = strlen(name);
char arr[50] = {'\0'};
try{
while(cnt != len){
if( (name[cnt] != ' ') && (name[cnt] != '\0') ){
if( ((name[cnt]<65) || (name[cnt]>129)) ){
fg = 1;
arr[cnt2] = name[cnt];
cnt2+= 1;
}
}
cnt++;
}
if(fg == 1)
throw arr;
return true;
}
catch(char chars[50]){
tot_exceptions+= 1;
cout<< endl<< "EXCEPTION OCCURRED!"<< endl<< "You've entered invalid character(s), like: ";
for(int cnt = 0; cnt<50; cnt++){
cout<< chars[cnt];
if(chars[cnt+1] != '\0')
cout<< ", ";
}
cout<< endl<< "RE-ENTER NAME: ";
return false;
}
}
static bool checkidcashier(const int id){ //function to check the entered id for exception handling.
try{
if( !(id>=750) && (id<754) )
throw id;
else
return true;
}
catch(...){
cout<< endl<< "EXCEPTION OCCURRED!"<< endl;
tot_exceptions+= 1;
cout<< "RE-ENTER ID: ";
fflush(stdin);
return false;
}
}
static bool checkmail(const char email[50]){ //function to check the entered name for exception handling.
int cnt2 = 0;
int fg = 0;
int len = strlen(email);
char arr[50] = {'\0'};
try{
for(int cnt=0;cnt<len;cnt++){
if( (email[cnt] != ' ') && (email[cnt] != '\0') ){
if((email[cnt]=='@' && email[cnt+1]=='g' && email[cnt+2]=='m' && email[cnt+3]=='a' && email[cnt+4]=='i' && email[cnt+5]=='l' && email[cnt+6]=='.' && email[cnt+7]=='c' && email[cnt+8]=='o' && email[cnt+9]=='m')){
return true;
}
else
fg = 1;
}
}
if (fg == 1){
string msg = "Kindly Enter a Valid EMAIL";
throw msg;
}
}
catch(string msg){
tot_exceptions+= 1;
cout<< endl<< "EXCEPTION OCCURRED!"<< endl<< msg<< endl
<< endl<< "RE-ENTER EMAIL: ";
return false;
}
}
int getexception() const{
return tot_exceptions;
}
};
int Exception_handling::tot_exceptions = 0;
//Class for Credit Card:
class CreditCard{
double tax;
double total;
long long CN;
int PS;
double amount;
public:
CreditCard(){
tax = 0.00;
total = 0.00;
CN = 0000;
PS = 0;
}
void addtax(double a){
tax = a*(12/100); //12% tax
total = a + tax;
}
bool Payment(const long long CC_N, const int pass, double amount){ //function to add the amount of bill as balance in the desired credit card
ifstream fin;
ofstream fout;
int count = 0;
fin.open("Bank.dat");
fout.open("BankTemp.dat");
CreditCard Temp;
if( !fin.is_open() ){
cout << "An Error occured while opening file!"<< endl;
return false;
}
else{
while(!fin.eof()){
fin.read((char *)&Temp, sizeof(Temp));
if( (CC_N == Temp.CN) && (pass == Temp.PS) ){
Temp.addtax(amount);
cout<< endl<< endl<< "Payment of Rs."<< Temp.total<<" Successful against this Credit Card!"<< endl<< endl<< endl;
Temp.amount+= Temp.total;
count = 1; //flag
fout.write((char *)&Temp, sizeof(Temp));
}
else
fout.write((char *)&Temp, sizeof(Temp));
}
fin.close();
fout.close();
remove("Bank.dat"); //this statement updated
rename("BankTemp.dat", "Bank.dat");
fflush(stdin);
}
if(count == 1){
return true;
}
if(count == 0){
cout<< endl<< "No such Card Found!"<< endl<< endl;
return false;
}
}
};
//function for password security:
void InputPassword(char p[20]){ //function to take password in the form of asterisks
char ch;
int i = 0;
while(1){
ch = getch();
if(ch == 13)
break;
else if(ch == '\b'){
if(i > 0){
i--;
p[i] = '\0';
cout << "\b \b";
}
}
else{
p[i] = ch;
cout << "*";
i++;
}
}
}
//converting an array of char to float:
float formnum(char pass[5]){
int num = 0;
int cnt = 0;
float val = 0;
int dig = 0, mult = 1;
while(pass[cnt]!= '\0'){
dig+= 1;
cnt++;
}
cnt = (dig-1);
while(cnt != -1){
val = pass[cnt] - 48;
num = num + (val * mult);
mult*= 10;
cnt--;
}
return num;
}
//Class for items:
class Items{
char name[60];
int quant;
float price;
long id;
public:
Items(){}
Items(char nam[60], int quantity, float price){
strcpy(name, nam);
this->quant = quantity;
this->price = price;
}
long getid() const{
return id;
}
void setprice(const float price){
this->price = price;
}
void setquant(const int quant){
this->quant = quant;
}
void setname(char const nme[60]){
strcpy(name, nme);
}
int getquant(){
return quant;
}
void showproducts(){
cout<< (*this);
}
void showproducts(int){ //function to display the info of product in the bill
cout << "ID: " << id;
cout << "\tName: " << name;
cout << "\tPrice: " << price<< endl;
}
float getprice(){
return price;
}
char* getname(){
char *ptr = &name[0];
return ptr;
}
void getproducts(const char name[60], const float price, const int quant){
strcpy(this->name, name);
this->quant = quant;
this->price = price;
}
bool storeprod() const{ //to add a new item in the of inventory (2 files)
if( (price == 0) && (name == "-") ){
cout << "PRODUCT NOT INITIALISED"<< endl;
return false;
}
else{
ofstream fout, fout2;
fout.open("Inventory.dat", ios::app);
fout2.open("Inventorymain.dat", ios::app);
fout.write((char *)this, sizeof(*this));
fout2.write((char *)this, sizeof(*this));
fout.close();
fout2.close();
return true;
}
}
void deletepro(const long ID){ //to delete a new item in the of inventory (2 files)
ifstream fin;
ofstream fout, fout2;
fin.open("Inventory.dat");
if (!fin.is_open()){
cout << "File Not Opened!";
}
else{
fout.open("tempfile.dat", ios::out);
fout2.open("tempfile2.dat", ios::out);
fin.read((char *)this, sizeof(*this));
while(!fin.eof())
{
if (id == ID){
cout << "\n\nProduct: " << name << " Deleted Successfully!"<< endl<< endl;
}
else{
fout.write((char *)this, sizeof(*this));
fout2.write((char *)this, sizeof(*this));
}
fin.read((char *)this, sizeof(*this));
}
fin.close();
fout.close();
fout2.close();
remove("Inventory.dat");
rename("tempfile.dat", "Inventory.dat");
remove("Inventorymain.dat");
rename("tempfile2.dat", "Inventorymain.dat");
}
}
bool setid(){ //function to assign ID to each item of the inventory, 1st ID = 1
ifstream fin;
Items Temp;
fin.open("Inventory.dat");
if(fin.is_open()){
while(!fin.eof()){
if( fin.read((char *)&Temp, sizeof(Temp)) );
}
id = (Temp.id) + 1;
fin.close();
cout<< endl<< "Assigned-ID is: "<< id<< endl;
return true;
}
else{
cout<< endl<< "NEW FILE IS NOW BEING CREATED!"<< endl;
id = 1;
cout<< endl<< "Assigned-ID is: "<< id << endl;
return false;
}
}
//operator overloading:
friend operator <<(ostream &out, Items Temp){ //to display the information of a specific product
out << "ID: " << Temp.id;
out << "\tName: " << Temp.name;
out << "\tPrice: " << Temp.price;
out << "\tQuantity: " << Temp.quant <<endl;
}
};
//Class for the inventory:
class Inventory{
Items *Item;
static int num_diffprod;
public:
Inventory(){
Item = NULL;
}
void setitem_ptr(Items &Itemm){ //to set the pointer of each item which we want to work on from the inventory
Item = &Itemm;
}
void clritem_ptr(){
Item = NULL;
}
static int noofProducts(){
ifstream fin;
Items Temp;
fin.open("Inventory.dat",ios::in);
fin.read((char*)&Temp,sizeof(Temp));
while(!fin.eof()){
num_diffprod+= 1;
fin.read((char*)&Temp,sizeof(Temp));
}
fin.close();
return num_diffprod;
}
void updateinv(const long ID){ //function to update the information of the specific product
fstream file;
char nme[60];
float prc;
int quan;
Items Temp;
file.open("Inventory.dat", ios::in | ios::out | ios::ate);
file.seekg(0); //bringing pointer of file at the starting of record (first line first character)
file.read((char *)&Temp, sizeof(Temp));
while(!file.eof())
{
if(Temp.getid() == ID){
char opt;
fflush(stdin);
cout<< endl<< "UPDATING INFORMATION OF THE PRODUCT WITH ID: "<< ID<< endl
<< "1 = Update Product-Name"<< endl<< "2 = Update Product-Price"<< endl<< "3 = Update Product-Quantity"<< endl<< "OPT: ";
opt = getch();
fflush(stdin);
if(opt == '1'){
cout << endl<< "Product-Name: ";
cin.getline(nme, 60);
Temp.setname(nme);
}
else if(opt == '2'){
cout << endl<< "Product-Price: ";
cin>> prc;
Temp.setprice(prc);
}
else if(opt == '3'){
cout << endl<< "Product-Quantity: ";
cin>> quan;
Temp.setquant((Temp.getquant()+quan));
}
else{
cout<< endl<< "Invalid Input!"<< endl;
}
int b = file.tellp();
file.seekp(b - sizeof(Temp)); //bringing character back to the state being updated
file.write((char *)&Temp, sizeof(Temp));
}
file.read((char *)&Temp, sizeof(Temp));
}
}
void decrement_quant(const long ID){ //function to do a decrement of the specific item from the inventory when sold
ifstream fin;
ofstream fout;
Items Temp;
fin.open("Inventory.dat");
fout.open("Inventorytemp.dat");
if(!fin.is_open()){
cout << endl<< "File Not Opened!"<< endl;
}
else{
while(!fin.eof()){
if(fin.read((char *)&Temp, sizeof(Temp))){
if( Temp.getid() == ID ){
int quant = Temp.getquant() - 1;
Temp.setquant(quant);
fout.write((char *)&Temp, sizeof(Temp));
}
else
fout.write((char *)&Temp, sizeof(Temp));
}
}
}
fin.close();
fout.close();
remove("Inventory.dat");
rename("Inventorytemp.dat", "Inventory.dat");
}
void viewallprod(){ //function to view the current status with all the items of the inventory
ifstream fin;
Items Temp;
fin.open("Inventory.dat");
if(!fin.is_open()){
cout << "File Not Opened!"<< endl;
}
else{
while(!fin.eof())
{
if(fin.read((char *)&Temp, sizeof(Temp))){
Temp.showproducts();
}
}
}
fin.close();
}
static void display_specificprod(const long ID){ //function to display the current status of the item specific item of the inventory
ifstream fin;
int count = 0;
Items Temp;
fin.open("Inventory.dat", ios::in);
if(!fin.is_open()){
cout << "File Not Opened!"<< endl;
}
else{
fin.read((char *)&Temp, sizeof(Temp));
while(!fin.eof())
{
if(Temp.getid() == ID){
Temp.showproducts();
count++;
}
fin.read((char *)&Temp, sizeof(Temp));
}
if (count == 0){
cout << "Product Not Found!"<< endl;
}
}
fin.close();
}
static void display_specificprod(const long ID, int){ //function overloaded for the display of specific item for the customer
ifstream fin;
int count = 0;
Items Temp;
fin.open("Inventory.dat", ios::in);
if(!fin.is_open()){
cout << "File Not Opened!"<< endl;
}
else{
fin.read((char *)&Temp, sizeof(Temp));
while(!fin.eof())
{
if(Temp.getid() == ID){
Temp.showproducts(1);
count++;
}
fin.read((char *)&Temp, sizeof(Temp));
}
if (count == 0){
cout << "Product Not Found!"<< endl;
}
}
fin.close();
}
static float check_availability(const long ID){ //function to check the presence of the specific item from the inventory
ifstream fin;
Items Temp;
fin.open("Inventory.dat", ios::in);
if(!fin.is_open()){
cout << "File Not Opened!"<< endl;
}
else{
fin.read((char *)&Temp, sizeof(Temp));
while(!fin.eof())
{
if( (Temp.getid() == ID) && (Temp.getquant() > 0) ){
fin.close();
return (Temp.getprice());
}
fin.read((char *)&Temp, sizeof(Temp));
}
cout << endl<< "Product Not Found!"<< endl;
fin.close();
return 0;
}
}
};
//Class for the customer:
class Customer{
int tot_items;
char bill_no[8];
double bill;
int count_cust;
public:
friend operator<<(ostream &out, Customer &cust){
cout<< endl<< "TOTAL-ITEMS: "<< cust.tot_items;
cout<< endl<< "BILL-NUMBER: ";
for(int cnt = 0; cnt< 8; cnt++)
cout<< cust.bill_no[cnt];
cout<< endl<< "BILL: Rs."<< cust.bill<< endl;
}
char getbill_no(const int cnt) const{
return bill_no[cnt];
}
char* getbill_address(){
char *ptr = &bill_no[0];
return ptr;
}
Customer(){
for(int cnt = 0; cnt<8; cnt++){
bill_no[cnt] = '\0';
}
bill = 0;
tot_items = 0;
count_cust = 0;
}
int gettot_items() const{
return tot_items;
}
double get_billamount(){
return bill;
}
int getcount_cust(){
return count_cust;
}
bool generateBillno(){ //generates bill number according to today's date
ifstream fcheck;
fcheck.open("Inventory.dat");
if( !fcheck.is_open() ){
cout<< endl<< "No items are available in the Inventory."<< endl<< "FAILED TO ASSIGN BILL-NUMBER!"<< endl;
return false;
}
else{
fcheck.close();
bill = 0;
tot_items = 0;
int day, month, count, i;
time_t now;
struct tm nowLocal;
now = time(NULL);
nowLocal = *localtime(&now);
day = nowLocal.tm_mday;
month = nowLocal.tm_mon + 1;
Customer Temp;
ifstream in;
in.open("Bill.dat");
if(!in.is_open()){
cout << "New Biling-file is being created!"<< endl<< endl<< endl<< "Proceeding with the new customer . . ."<< endl<< endl<< endl;
}
else{
while(!in.eof()){
if( in.read((char*)&Temp, sizeof(Temp)) );
}
in.close();
count_cust = Temp.getcount_cust() + 1;
}
if( (Temp.bill_no[2] != ((day/10) + 48)) || (Temp.bill_no[3] != ((day%10) + 48)) )
count_cust = 1;
bill_no[0] = (month/10) + 48;
bill_no[1] = (month%10) + 48;
bill_no[2] = (day/10) + 48;
bill_no[3] = (day%10) + 48;
i = 7;
count = count_cust;
while(i != 3){
bill_no[i] = (count%10) + 48;
count = count/10;
i--;
}
return true;
}
}
void calculateBill(const float price){ //function to add the price of each item in the customer's bill
bill = bill + price;
if(price>0){
tot_items++;
}
}
void displayallrecord(){ //display the bill of each customer
ifstream fin;
fin.open("Bill.dat");
if(!fin.is_open())
cout << "File could not open!"<< endl;
else{
cout<< endl<< "DISPLAYING THE RECORDS: ";
while(!fin.eof()){
if(fin.read((char*)this, sizeof(*this))){
cout << endl<< "TOTAL-ITEMS: "<< tot_items
<< endl<< "BILL-NUMBER: ";
for(int j = 0; j < 8; j++)
cout << bill_no[j];
cout << endl<< "BILL: Rs."<< bill<< endl<< endl<< endl;
}
}
fin.close();
}
}
void AddRecord(){ //will add this bill of the customer
ofstream fout;
fout.open("Bill.dat", ios :: app);
if(!fout.is_open())
cout << "File could not open!"<< endl;
else{
fout.write((char*)this, sizeof(*this));
fout.close();
cout<< endl<< "Billing-Info has been added successfully! " << endl << endl;
}
}
void viewreciept(const long *ID, const int num) const{ //to view bill for recent customer
cout<< "BILLING-ID: ";
for(int j = 0; j < 8; j++)
cout << bill_no[j];
cout << endl;
for(int cnt = 0; cnt< num; cnt++){
Inventory::display_specificprod(*(ID + cnt), 1);
}
cout << endl;
}
};
//Class for the employees:
class Employees{ //abstract class
int id;
char address[100], email[50], pass[20];
public:
Employees(){
id = 0;
}
void setaddress(const char add[100]){
strcpy(address, add);
}
void setemail(const char mail[50]){
strcpy(email, mail);
}
void setpswd(const char pswd[20]){
strcpy(pass,pswd);
}
char* getadd(){
char *ptr = &address[0];
return ptr;
}
char* getmail(){
char *ptr = &email[0];
return ptr;
}
char* getpswd(){
char *ptr = &pass[0];
return ptr;
}
void setidm(const int identity){
id = identity;
}
int getid() const{
return id;
}
virtual void viewrecord() = 0;
};
//Class for the cashier
class Cashier : public Employees{
long customers;
Customer *C;
long long Mobile;
char name[50];
public:
void setcustom_ptr(Customer &Cust){ //Cashier me customer se related koi bhi functionality call krne se pehle ye function call krna must hai
C = &Cust;
}
void setname(const char nme[50]){
strcpy(name, nme);
}
void setMobile(const long long mob){
Mobile = mob;
}
bool checkitem(const long ID){ //calls check_availability for each item from inventory and call another func to add it's price of available
float price;
price = Inventory::check_availability(ID);
C->calculateBill(price);
return (price > 0);
}
long long getcell(){
return Mobile;
}
void freecustom_ptr(){ //to free the pointer of the customer
C = NULL;
}
int setid(){
ifstream fin;
Cashier Temp;
int iden;
fin.open("Employees.dat");
if(fin.is_open()){
while(!fin.eof()){
if( fin.read((char *)&Temp, sizeof(Temp)) );
}
iden = (Temp.getid()) + 1;
fin.close();
}
else{
cout<< endl<< "NEW FILE IS NOW BEING CREATED!"<< endl;
iden = 750; //first cashier's ID = 750
}
cout<< endl<< "Assigned-ID is: "<< iden << endl;
return iden;
}
char* setpass(int rnd){ //automatic generator for password on the basis of First name, Cashier-id, & 3 random number
char password[20] = {'\0'};
int random = rnd;
int cnt = 0, data[3] = {0}, cnt2 = 0;
int num;
char *ptr;
while(1){
if( name[cnt] != ' ' ){
password[cnt] = name[cnt];
}
else{
break;
}
cnt++;
}
int a = cnt;
num = getid();
cnt = 2;
while(cnt!= -1){
data[cnt] = (num%10);
num/= 10;
cnt--;
}
num = 0;
cnt = a;
a = cnt + 3;
for(; cnt<a; cnt++){
password[cnt] = (data[cnt2] + 48);
cnt2++;
}
a = cnt;
cnt2 = 0;
num = random;
cnt = 2;
while(num != 0){
data[cnt] = (num%10);
num/= 10;
cnt-= 1;
}
cnt = a;