-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.cpp
1144 lines (922 loc) · 32.4 KB
/
Project.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<fstream>
#include<string>
#include<conio.h>
#include<windows.h>
using namespace std;
int phase1_reg_hour_unit_priceD = NULL;
int phase1_peak_hours_unit_priceD = NULL;
int phase1_percentage_of_taxD = NULL;
int phase1_fixed_chargesD = NULL;
int phase1_reg_hour_unit_priceC = NULL;
int phase1_peak_hours_unit_priceC = NULL;
int phase1_percentage_of_taxC = NULL;
int phase1_fixed_chargesC = NULL;
int phase3_reg_hour_unit_priceD = NULL;
int phase3_peak_hours_unit_priceD = NULL;
int phase3_percentage_of_taxD = NULL;
int phase3_fixed_chargesD = NULL;
int phase3_reg_hour_unit_priceC = NULL;
int phase3_peak_hours_unit_priceC = NULL;
int phase3_percentage_of_taxC = NULL;
int phase3_fixed_chargesC = NULL;
// This function will calculate the string length
int StringLenght(char* str)
{
int stringLen = 0;
for (char* temp = str; *temp != '\0'; temp++)
stringLen++;
return stringLen;
} // to calculate lenght of string
// This function will return the string
char* GetStringFromBuffer(char* str)
{
int strLen = StringLenght(str);
char* mystr = 0;
if (strLen > 0)
{
mystr = new char[strLen + 1];
for (int i = 0; i < strLen; i++)
{
mystr[i] = str[i];
}
mystr[strLen] = '\0';
}
return mystr;
} // function to get string from buffer
// This function will load employee's IDs and Passwords
void LoadEmployeeData(char**& employee_username, char**& employee_password, int& totalemployees)
{
ifstream input_employeedata("emp.txt");
if (input_employeedata.is_open())
{
employee_username = new char* [4];
employee_password = new char* [4];
char temp[100];
int i = 0;
while (!input_employeedata.eof())
{
input_employeedata.getline(temp, 100, ',');
employee_username[i] = GetStringFromBuffer(temp);
input_employeedata.getline(temp, 100);
employee_password[i] = GetStringFromBuffer(temp);
i++;
totalemployees = i;
}
input_employeedata.close();
}
else
{
cout << "OPS!! DATA NOT FOUND\n";
}
}
// This function is to show data on console
void ShowEmployeeData(char** employee_username, char** employee_password, int totalemployees)
{
int index = NULL;
for (; index < totalemployees; index++)
cout << employee_username[index] << " " << employee_password[index] << endl;
}
// This function will load the data of customer
void LoadCustomerData(int& _totalCustomers, char**& customer_ID, char**& customer_DOB, char**& customer_name, char**& customer_address, char**& customer_ContactNum, char**& customerType, char**& meterType, char**& connectionDate, int*& regular_hours, int*& peak_hours, char**& customerPassword)
{
ifstream input_customerdata("cus.txt");
if (input_customerdata.is_open())
{
customer_ID = new char* [10];
customer_DOB = new char* [10];
customer_name = new char* [10];
customer_address = new char* [10];
customer_ContactNum = new char* [10];
customerType = new char* [10];
meterType = new char* [10];
connectionDate = new char* [10];
regular_hours = new int[10];
peak_hours = new int[10];
customerPassword = new char* [10];
char temp[300];
int i = 0;
while (!input_customerdata.eof())
{
input_customerdata.getline(temp, 100, ',');
customer_ID[i] = GetStringFromBuffer(temp);
input_customerdata.getline(temp, 100, ',');
customer_DOB[i] = GetStringFromBuffer(temp);
customerPassword[i] = GetStringFromBuffer(temp);
input_customerdata.getline(temp, 100, ',');
customer_name[i] = GetStringFromBuffer(temp);
input_customerdata.getline(temp, 100, ',');
customer_address[i] = GetStringFromBuffer(temp);
input_customerdata.getline(temp, 100, ',');
customer_ContactNum[i] = GetStringFromBuffer(temp);
input_customerdata.getline(temp, 100, ',');
customerType[i] = GetStringFromBuffer(temp);
input_customerdata.getline(temp, 100, ',');
meterType[i] = GetStringFromBuffer(temp);
input_customerdata.getline(temp, 100, ',');
connectionDate[i] = GetStringFromBuffer(temp);
int number;
input_customerdata >> number;
regular_hours[i] = number;
input_customerdata.ignore();
input_customerdata >> number;
peak_hours[i] = number;
i++;
}
_totalCustomers = i;
input_customerdata.close();
}
else
{
cout << "OPS!! \n NO DATA FOUND\n";
}
}
// This function will show the data of customer on console
void ShowLaodedCustomers(int _totalCustomers, char** customer_ID, char** customer_DOB, char** customer_name, char** customer_address, char** customer_ContactNum, char** customerType, char** meterType, char** connectionDate, int* regular_hours, int* peak_hours)
{
//if (customer_ID[index] && customer_DOB[index] && customer_name[index] && customer_address[index] && customer_ContactNum[index] && customerType[index] && meterType[index] && connectionDate[index] && regular_hours[index] && peak_hours[index])
int index = NULL;
for (; index < _totalCustomers; index++)
{
cout << customer_ID[index] << " " << customer_DOB[index] << " " << customer_name[index] << " " << customer_address[index] << " " << customer_ContactNum[index] << " " << customerType[index] << " " << meterType[index] << " " << connectionDate[index] << " " << regular_hours[index] << " " << peak_hours[index] << endl;
}
}
// This function will take the logg in information of user
void Login(char*& loggedin_Username, char*& loggedin_Password)
{
char buffer[100];
cout << "Username: ";
cin.ignore();
cin.getline(buffer, 100);
loggedin_Username = GetStringFromBuffer(buffer);
cout << "Password: ";
cin.getline(buffer, 100);
loggedin_Password = GetStringFromBuffer(buffer);
}
// This function will verify the employee's usernmae and password
bool Employee_Verification(char** employee_username, char** employee_password, char* loggedin_Username, char* loggedin_Password, int totalEmployees, int& foundIndex)
{
bool correctUsername = false;
bool correctPassword = false;
for (int i_index = NULL; i_index < totalEmployees; i_index++)
{
char* temp = employee_username[i_index];
if (StringLenght(temp) == StringLenght(loggedin_Username))
{
for (int j_index = NULL; j_index < StringLenght(temp); j_index++)
{
correctUsername = false;
if (temp[j_index] == loggedin_Username[j_index])
{
correctUsername = true;
}
}
if (correctUsername == true)
{
char* temp2 = employee_password[i_index];
for (int j_index = NULL; j_index < StringLenght(temp2); j_index++)
{
correctPassword = false;
if (temp2[j_index] == loggedin_Password[j_index])
{
correctPassword = true;
foundIndex = i_index;
}
else
{
foundIndex = NULL;
}
}
}
if (correctPassword == true)
{
return true;
}
}
else
{
return false;
}
}
}
// This function will let the employyee to change his password
void ChangePassword(char**& employee_username, char**& employee_password, int totalEmployees)
{
char buffer[100];
cout << "Enter Your Username: ";
cin >> buffer;
char* loggedin_Username = GetStringFromBuffer(buffer);
cout << "Enter your current Pssword: ";
cin >> buffer;
char* loggedin_Password = GetStringFromBuffer(buffer);
int foundIndex = NULL;
if (Employee_Verification(employee_username, employee_password, loggedin_Username, loggedin_Password, totalEmployees, foundIndex) == true)
{
employee_password[foundIndex] = NULL;
cout << "Enter new Password: ";
cin.ignore();
cin.getline(buffer, 100);
employee_password[foundIndex] = GetStringFromBuffer(buffer);
ofstream put("emp.txt");
for (int index = 0; index < totalEmployees; index++)
{
put << employee_username[index] << "," << employee_password[index] << endl;
}
put.close();
}
else
{
cout << "No Such Username Exist\n";
}
}
// This function will regenerate the tarrif file after change
void Put_Tarriff(ofstream& put)
{
put << "1Phase" << "," << phase1_reg_hour_unit_priceD << "," << phase1_peak_hours_unit_priceD << "," << phase1_percentage_of_taxD << "," << phase1_fixed_chargesD << endl;
put << "1Phase" << "," << phase1_reg_hour_unit_priceC << "," << phase1_peak_hours_unit_priceC << "," << phase1_percentage_of_taxC << "," << phase1_fixed_chargesC << endl;
put << "3Phase" << "," << phase3_reg_hour_unit_priceD << "," << phase3_peak_hours_unit_priceD << "," << phase3_percentage_of_taxD << "," << phase3_fixed_chargesD << endl;
put << "3Phase" << "," << phase3_reg_hour_unit_priceC << "," << phase3_peak_hours_unit_priceC << "," << phase3_percentage_of_taxC << "," << phase3_fixed_chargesC << endl;
}
// This function will input tarriff attributes of domestic phase 1 customer
void Phase1_Tarrif_for_D(int& phase1_reg_hour_unit_priceD, int& phase1_peak_hours_unit_priceD, int& phase1_percentage_of_taxD, int& phase1_fixed_chargesD, ifstream& tarriff_input)
{
char buffer[100];
tarriff_input.getline(buffer, 100, ',');
tarriff_input >> phase1_reg_hour_unit_priceD;
tarriff_input.ignore();
tarriff_input >> phase1_peak_hours_unit_priceD;
tarriff_input.ignore();
tarriff_input >> phase1_percentage_of_taxD;
tarriff_input.ignore();
tarriff_input >> phase1_fixed_chargesD;
}
// This function will update tarriff attributes of domestic phase 1 customer
void Phase1_Tarrif_for_D(int& phase1_reg_hour_unit_priceD, int& phase1_peak_hours_unit_priceD, int& phase1_percentage_of_taxD, int& phase1_fixed_chargesD)
{
cout << "Enter Regular Hour Unit Price: ";
cin >> phase1_reg_hour_unit_priceD;
phase1_peak_hours_unit_priceD = 0;
cout << "Enter Percentage of Tax: ";
cin >> phase1_percentage_of_taxD;
cout << "Enter Fixed Charges";
cin >> phase1_fixed_chargesD;
}
// This function will input tarriff attributes of commercial phase 1 customer
void Phase1_Tarrif_for_C(int& phase1_reg_hour_unit_priceC, int& phase1_peak_hours_unit_priceC, int& phase1_percentage_of_taxC, int& phase1_fixed_chargesC, ifstream& tarriff_input)
{
char buffer[100];
tarriff_input.getline(buffer, 100, ',');
tarriff_input >> phase1_reg_hour_unit_priceC;
tarriff_input.ignore();
tarriff_input >> phase1_peak_hours_unit_priceC;
tarriff_input.ignore();
tarriff_input >> phase1_percentage_of_taxC;
tarriff_input.ignore();
tarriff_input >> phase1_fixed_chargesC;
}
// This function will update tarriff attributes of commercial phase 1 customer
void Phase1_Tarrif_for_C(int& phase1_reg_hour_unit_priceC, int& phase1_peak_hours_unit_priceC, int& phase1_percentage_of_taxC, int& phase1_fixed_chargesC)
{
cout << "Enter Regular Hour Unit Price: ";
cin >> phase1_reg_hour_unit_priceC;
phase1_peak_hours_unit_priceD = 0;
cout << "Enter Percentage of Tax: ";
cin >> phase1_percentage_of_taxC;
cout << "Enter Fixed Charges";
cin >> phase1_fixed_chargesC;
}
// This function will input tarriff attributes of domestic phase 3 customer
void Phase3_Tarrif_for_D(int& phase3_reg_hour_unit_priceD, int& phase3_peak_hours_unit_priceD, int& phase3_percentage_of_taxD, int& phase3_fixed_chargesD, ifstream& tarriff_input)
{
char buffer[100];
tarriff_input.getline(buffer, 100, ',');
tarriff_input >> phase3_reg_hour_unit_priceD;
tarriff_input.ignore();
tarriff_input >> phase3_peak_hours_unit_priceD;
tarriff_input.ignore();
tarriff_input >> phase3_percentage_of_taxD;
tarriff_input.ignore();
tarriff_input >> phase3_fixed_chargesD;
}
// This function will update tarriff attributes of domestic phase 3 customer
void Phase3_Tarrif_for_D(int& phase3_reg_hour_unit_priceD, int& phase3_peak_hours_unit_priceD, int& phase3_percentage_of_taxD, int& phase3_fixed_chargesD)
{
cout << "Enter Regular hours Price: ";
cin >> phase3_reg_hour_unit_priceD;
cout << "Enter Peak Hours Price: ";
cin >> phase3_peak_hours_unit_priceD;
cout << "Enter Pecentage of Tax: ";
cin >> phase3_percentage_of_taxD;
cout << "Enter Fixed Charges: ";
cin >> phase3_fixed_chargesD;
}
// This function will input tarriff attributes of commercial phase 3 customer
void Phase3_Tarrif_for_C(int& phase3_reg_hour_unit_priceC, int& phase3_peak_hours_unit_priceC, int& phase3_percentage_of_taxC, int& phase3_fixed_chargesC, ifstream& tarriff_input)
{
char buffer[100];
tarriff_input.getline(buffer, 100, ',');
tarriff_input >> phase3_reg_hour_unit_priceC;
tarriff_input.ignore();
tarriff_input >> phase3_peak_hours_unit_priceC;
tarriff_input.ignore();
tarriff_input >> phase3_percentage_of_taxC;
tarriff_input.ignore();
tarriff_input >> phase3_fixed_chargesC;
}
// This function will update tarriff attributes of commercial phase 3 customer
void Phase3_Tarrif_for_C(int& phase3_reg_hour_unit_priceC, int& phase3_peak_hours_unit_priceC, int& phase3_percentage_of_taxC, int& phase3_fixed_chargesC)
{
cout << "Enter Regular hours Price: ";
cin >> phase3_reg_hour_unit_priceC;
cout << "Enter Peak Hours Price: ";
cin >> phase3_peak_hours_unit_priceC;
cout << "Enter Pecentage of Tax: ";
cin >> phase3_percentage_of_taxC;
cout << "Enter Fixed Charges: ";
cin >> phase3_fixed_chargesC;
}
// This function will prompt employyee to enter billing info of every customer
void BillingInfo(char**& id, int totalCustomers, char** meterType, char** customerType, bool*& Status, int*& TotalBill)
{
int* BillingMonth = new int[totalCustomers];
int* SalesTax = new int[totalCustomers];;
int* FixedCharges = new int[totalCustomers];;
//TotalBill = new int[totalCustomers];;
int* DueDate = new int[totalCustomers];;
Status = new bool[totalCustomers];;
int* reading_entry_date = new int[totalCustomers];
int* currentRegular_meterReading = new int[totalCustomers];
int* currentPeak_meterReading = new int[totalCustomers];
int* Regular_costperunit = new int[totalCustomers];
int* Peak_costperunit = new int[totalCustomers];
int* regularconsumedunits = new int[totalCustomers];
int* peakconsumedunits = new int[totalCustomers];
int* currentmeterRead = new int[totalCustomers];
int* previousmeterRead = new int[totalCustomers];
for (int i = 0; i < totalCustomers; i++)
{
previousmeterRead[i] = 0;
}
int* costperunits = new int[totalCustomers];
int* consumedUnits = new int[totalCustomers];
ofstream OutputBill("BillingInfo.txt");
if (OutputBill.is_open())
{
for (int index = NULL; index < totalCustomers; index++)
{
char buffer[100];
OutputBill << id[index] << ",";
int number;
cout << "Billing Month: ";
cin >> number;
BillingMonth[index] = number;
OutputBill << BillingMonth[index] << ",";
currentmeterRead[index] = 0;
//OutputBill << currentmeterRead[index] << ",";
cout << "Reading Entry Date: ";
cin >> number;
reading_entry_date[index] = number;
//OutputBill << reading_entry_date[index] << ",";
if (meterType[index][0] == '1')
{
cout << "Current Meter Reading for regular hours: ";
cin >> number;
currentRegular_meterReading[index] = number;
//OutputBill << currentRegular_meterReading[index] << ",";
if (customerType[index][0] == 'D')
{
FixedCharges[index] = phase1_fixed_chargesD;
//OutputBill << FixedCharges[index]<<",";
Peak_costperunit[index] = phase1_peak_hours_unit_priceD;
//OutputBill << Peak_costperunit[index]<<",";
Regular_costperunit[index] = phase1_reg_hour_unit_priceD;
//OutputBill << Regular_costperunit[index]<<",";
consumedUnits[index] = currentRegular_meterReading[index];
OutputBill << consumedUnits[index] << ",";
int currentmonthunits = consumedUnits[index] - previousmeterRead[index];
//OutputBill << previousmeterRead[index] << ",";
//OutputBill << currentmonthunits << ",";
SalesTax[index] = phase1_percentage_of_taxD;
//OutputBill << SalesTax[index]<<",";
TotalBill[index] = currentmonthunits * SalesTax[index] / 100 + FixedCharges[index];
OutputBill << TotalBill[index] << ",";
}
else
{
if (customerType[index][0] == 'C')
{
FixedCharges[index] = phase1_fixed_chargesC;
Peak_costperunit[index] = phase1_peak_hours_unit_priceC;
Regular_costperunit[index] = phase1_reg_hour_unit_priceC;
//OutputBill << Regular_costperunit[index] << ",";
consumedUnits[index] = currentRegular_meterReading[index];
OutputBill << consumedUnits[index] << ",";
int currentmonthunits = consumedUnits[index] - previousmeterRead[index];
//OutputBill << previousmeterRead[index] << ",";
//OutputBill << currentmonthunits;
SalesTax[index] = phase1_percentage_of_taxC;
TotalBill[index] = currentmonthunits * SalesTax[index] / 100 + FixedCharges[index];
OutputBill << TotalBill[index] << ",";
}
}
}
else
{
if (meterType[index][0] == '3')
{
cout << "Current Meter Reading for regular hours: ";
cin >> number;
currentRegular_meterReading[index] = number;
//OutputBill << currentRegular_meterReading[index] << ",";
cout << "Current Meter Reading for Peak Hours: ";
cin >> number;
currentPeak_meterReading[index] = number;
if (customerType[index][0] == 'D')
{
FixedCharges[index] = phase3_fixed_chargesD;
//OutputBill << FixedCharges[index] << ",";
// price
Peak_costperunit[index] = phase3_peak_hours_unit_priceD;
//OutputBill << Peak_costperunit[index] << ",";
// price
Regular_costperunit[index] = phase3_reg_hour_unit_priceD;
//OutputBill << Regular_costperunit[index] << ",";
consumedUnits[index] = currentRegular_meterReading[index] + currentPeak_meterReading[index];
OutputBill << consumedUnits[index] << ",";
int currentmonthunits = consumedUnits[index] - previousmeterRead[index];
//OutputBill << previousmeterRead[index] << ",";
//OutputBill << currentmonthunits << ",";
SalesTax[index] = phase3_percentage_of_taxD;
//OutputBill << SalesTax[index] << ",";
TotalBill[index] = currentmonthunits * SalesTax[index] / 100 + FixedCharges[index];
OutputBill << TotalBill[index] << ",";
}
else
{
if (customerType[index][0] == 'C')
{
FixedCharges[index] = phase3_fixed_chargesC;
// Price
Peak_costperunit[index] = phase3_peak_hours_unit_priceC;
//OutputBill << Peak_costperunit[index] << ",";
Regular_costperunit[index] = phase3_reg_hour_unit_priceC;
//OutputBill << Regular_costperunit[index] << ",";
consumedUnits[index] = currentRegular_meterReading[index] + currentPeak_meterReading[index];
OutputBill << consumedUnits[index] << ",";
int currentmonthunits = consumedUnits[index] - previousmeterRead[index];
SalesTax[index] = phase3_percentage_of_taxC;
TotalBill[index] = currentmonthunits * SalesTax[index] / 100 + FixedCharges[index];
OutputBill << TotalBill[index] << ",";
}
}
}
}
DueDate[index] = reading_entry_date[index] + 7;
OutputBill << DueDate[index] << ",";
Status[index] = false;
OutputBill << Status[index] << endl;
}
}
else
{
cout << "BillingInfo File cannot be openned.\n";
}
}
// This function will load the customer's billing info
void LaodBillInfo(char**& ID, int*& BillingMonth, int*& ConsumedUnits, int*& Totalbill, int*& DueDate, bool*& Status, int totalcustomers)
{
char buffer[100];
ifstream input("BillingInfo.txt");
if (input.is_open())
{
for (int i = 0; i < totalcustomers; i++)
{
input.getline(buffer, 100, ',');
ID[i] = GetStringFromBuffer(buffer);
int number;
input >> BillingMonth[i];
input.ignore();
input >> ConsumedUnits[i];
input.ignore();
input >> Totalbill[i];
input.ignore();
input >> DueDate[i];
input.ignore();
input >> Status[i];
}
}
}
// This function will show bill info
void ViewBill(char** id, bool* Status, int* TotalBill, int index)
{
cout << id[index] << " ";
if (Status[index] == true)
cout << "Paid" << " ";
else
cout << "Un-Paid" << " ";
cout << " " << TotalBill[index] << endl;
}
// This function will show the status of all paid and upaid customers along with their bills
void VeiwCustomerBill(char** ID, char* id, int totalcustomers, bool* status, char** meterType, char** customerType, int* TotalBill)
{
bool found = false;
for (int i = 0; i < totalcustomers; i++)
{
char* temp = ID[i];
for (int j = 0; j < strlen(temp); j++)
{
found = false;
if (temp[j] == id[j])
{
found = true;
}
}
if (found == true)
{
if (status[i] == 1)
cout << "Status of " << temp << " is Paid" << " ";
else
if (status[i] == 0)
cout << "Status of " << temp << " is Un-Paid" << " ";
cout << "\nBill: " << TotalBill[i] << endl;
cout << "Customer Type: " << customerType[i] << endl;
cout << "Meter Type: " << meterType[i] << endl;
}
}
}
// This function will show the bill statistics
void BillStatistics(char** ID, bool* status, int totalcustomers, int* totalbill)
{
int unpaid = NULL;
int paid = NULL;
for (int i = 0; i < totalcustomers; i++)
{
if (status[i] == 0)
{
cout << ID[i] << "'s" << " bill " << totalbill[i] << " is unpaid";
unpaid = unpaid + totalbill[i];
cout << endl;
}
if (status[i] == 1)
{
cout << endl;
cout << ID[i] << "'s" << " bill " << totalbill[i] << " is Paid";
paid = paid + totalbill[i];
cout << endl;
}
}
cout << "Total amount of unapid bills is: " << unpaid;
cout << endl;
cout << "Total amount of paid bills is: " << paid;
}
// This function will led the employyee to change the status of customers who paid bill
void ChangeStatus(int index, bool* status)
{
status[index] = 1;
}
// This function will lead the employyeee to register new customer
void Register_New_Customer(int& totalcustomer)
{
ofstream put;
put.open("cus.txt", std::fstream::app);
string data;
cout << "Enter ID: ";
cin >> data;
put << endl << data << ",";
cout << "Enter Date Of Birth: ";
cin >> data;
put << data << ",";
cout << "Enter Name: ";
cin.ignore();
getline(cin, data);
put << data << ",";
cout << "Enter Address: ";
getline(cin, data);
put << data << ",";
cout << "Enter Contact Number: ";
cin >> data;
put << data << ",";
cout << "Enter Customer Type: ";
cin >> data;
put << data << ",";
cout << "Enter Meter Type: ";
cin >> data;
put << data << ",";
cout << "Enter Cd: ";
cin >> data;
put << data << ",";
cout << "Enter Regular Hours Consumption: ";
cin >> data;
put << data << ",";
cout << "Enter Peak Hours Consumption: ";
cin >> data;
put << data;
totalcustomer++;
}
// This function will find the customer and will return index
int FindCustomer(char** ID, char* id, int totalcustomers)
{
bool found = false;
for (int i = 0; i < totalcustomers; i++)
{
char* temp = ID[i];
found = false;
for (int j = 0; j < strlen(temp); j++)
{
if (temp[j] == id[j])
found = true;
else
break;
}
if (found == true)
{
return i;
}
}
}
// This function will verify customers log in ID and password
bool Verify_Customer(char** ID, char** customerpassword, char* loggedin_username, char* loggedin_password, int total_customers, int& foundIndex)
{
bool customerID = false;
bool customer_Password = false;
for (int index = NULL; index < total_customers; index++)
{
char* temp = ID[index];
char* newString = temp;
if (temp[0] == '\n')
{
int len = StringLenght(temp);
newString = new char[len];
int counter = 1;
int index = NULL;
for (; index < len; index++)
{
newString[index] = temp[counter];
counter++;
}
newString[index] = '\0';
}
temp = newString;
int check = NULL;
if (StringLenght(temp) == StringLenght(loggedin_username))
{
for (int j_index = NULL; j_index < StringLenght(temp); j_index++)
{
customerID = false;
if (temp[j_index] == loggedin_username[j_index])
{
customerID = true;
check++;
}
}
if (check == StringLenght(loggedin_username))
{
check = NULL;
char* _temp = customerpassword[index];
if (StringLenght(_temp) == StringLenght(loggedin_password))
{
for (int j_index = NULL; j_index < StringLenght(_temp); j_index++)
{
customer_Password = false;
if (_temp[j_index] == loggedin_password[j_index])
{
customer_Password = true;
check++;
}
}
if (check == StringLenght(loggedin_password))
{
foundIndex = index;
return true;
}
}
else
{
return false;
}
}
}
}
}
int main()
{
// D A T A I N I T I A L I Z A T I O N
// Employee Information
char** employee_Username = NULL; // 2D array to load employees list
char** employee_password = NULL; // 2D array to load employees's password
// Customer Information
char** ID = NULL; // customer ID
char** DOB = NULL; // Date of Birth of customer
char** name = NULL; // Name of customer
char** address = NULL; // Address of customer
char** contactNumber = NULL; // contact number
char** customerType = NULL; // customer type i.e. either commercial or domestic
char** meterType = NULL; // meter type i.e. 1phase meter or 3phase meter
char** connectionDate = NULL; // connection date
char** customerPassword = NULL; //customer's passwords array
int* regular_hours = NULL; // meter reading in regular hours
int* peak_hours = NULL; // meter reading on peak hours
int option = NULL; // choice
int totalCustomers = NULL;
int totalEmployees = NULL;
int* TotalBill = new int[10];
int* BillingMonth = new int[totalCustomers];
int* ConsumedUnits = new int[totalCustomers];
int* totalbill = new int[totalCustomers];
int* DueDate = new int[totalCustomers];
bool* billStatus = new bool[10];
bool* Status = new bool[totalCustomers];
// Laoding Customers Data
LoadCustomerData(totalCustomers, ID, DOB, name, address, contactNumber, customerType, meterType, connectionDate, regular_hours, peak_hours, customerPassword);
//ShowLaodedCustomers(totalCustomers, ID, DOB, name, address, contactNumber, customerType, meterType, connectionDate, regular_hours, peak_hours);
// Loading Tarriff Data
ifstream input_tarriff("TarrifTaxInfo.txt");
Phase1_Tarrif_for_D(phase1_reg_hour_unit_priceD, phase1_peak_hours_unit_priceD, phase1_percentage_of_taxD, phase1_fixed_chargesD, input_tarriff);
Phase1_Tarrif_for_C(phase1_reg_hour_unit_priceC, phase1_peak_hours_unit_priceC, phase1_percentage_of_taxC, phase1_fixed_chargesC, input_tarriff);
Phase3_Tarrif_for_D(phase3_reg_hour_unit_priceD, phase3_peak_hours_unit_priceD, phase3_percentage_of_taxD, phase3_fixed_chargesD, input_tarriff);
Phase3_Tarrif_for_C(phase3_reg_hour_unit_priceC, phase3_peak_hours_unit_priceC, phase3_percentage_of_taxC, phase3_fixed_chargesC, input_tarriff);
// Laoding Bill Info
char** id = new char* [totalCustomers];
LaodBillInfo(id, BillingMonth, ConsumedUnits, totalbill, DueDate, Status, totalCustomers);
cout << "\t\t\t\t\ LESO PROJETC\n";
cout << "\t\t\t\t\t Are you Employee or Customer \n \n";
cout << "\t\t\t\t\t For Employee Press 0 \n\t\t\t\t\t For Customer Press 1\n \n";
cin >> option;
if (option == 0)
{
LoadEmployeeData(employee_Username, employee_password, totalEmployees);
//ShowEmployeeData(employee_Username, employee_password, totalEmployees);
char* loggedin_Username;
char* loggedin_Password;
Login(loggedin_Username, loggedin_Password);
int foundEmployee = NULL;
if (Employee_Verification(employee_Username, employee_password, loggedin_Username, loggedin_Password, totalEmployees, foundEmployee) == true)
{
cout << "Login Successfull\n";
cout << "Press any Number (1-7) to continue......";
cin >> option;
while (option != 0)
{
cout << "\n\nFor Changing Password Press 1\nFor Registering new Customer Press 2\nFor Entring Billing Information Press 3\nFor Veiw Bill of Customer Press 4\n";
cout << "For Veiwing Statistics of Bills Press 5\nFor Updating Tarriff Information Press 6\nFor Changing Status of customer Press 7\nFor Exit Press 0\n";
cin >> option;
if (option == 1)
{
totalEmployees--;
ChangePassword(employee_Username, employee_password, totalEmployees);
cout << endl << "Password Changed Successfully\n";
}
else
{
if (option == 2)
{
Register_New_Customer(totalCustomers);
cout << endl << "New Customer Registered Successfully\n";
}
else
{
if (option == 3)
{
BillingInfo(ID, totalCustomers, meterType, customerType, billStatus, TotalBill);
cout << "Updated\n";
}
else
{
if (option == 4)
{
cout << "Enter ID: ";
char buffer[100];
cin >> buffer;
char* id;
id = GetStringFromBuffer(buffer);
VeiwCustomerBill(ID, id, totalCustomers, Status, meterType, customerType, totalbill);
}
else
{