-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISEProject.cpp
1797 lines (1653 loc) · 47.1 KB
/
ISEProject.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 <ctime>
#include <string>
#include <sstream>
using namespace std;
class Bill;
class LESCO;
class Costumer;
class Employee;
// ============================================ HELPER ============================================
class Helper
{
public:
static void CheckDateValidity(int year, int month, int date)
{
bool validDate = false;
int count = 0;
if (year > 999 && year <= 9999)
{
if (month <= 12)
{
if (date <= 31)
{
validDate = true;
}
else validDate = false;
}
}
if (validDate == true)
{
return;
}
else
{
cout << "Invalid Date!Enter again:\n";
cin >> year >> month >> date;
CheckDateValidity(year, month, date);
}
}
};
// ============================================ EMPLOYEE ============================================
class Employee
{
string UserName;
string Password;
public:
Employee();
void LoadDataFromFile(ifstream&);
void InputEmployeeData(string, string);
void SaveData(ofstream&);
bool CheckCredentials(string, string);
void ChangeStatus();
~Employee();
};
Employee::Employee() // Constructor
{
UserName = "0";
Password = "0";
}
// This will get data from "EmployeesData.txt"
void Employee::LoadDataFromFile(ifstream& inputEmployee)
{
string temp;
int count = 0;
getline(inputEmployee, UserName, ',');
getline(inputEmployee, Password);
}
void Employee::InputEmployeeData(string Name, string Pass)
{
UserName = Name;
Password = Pass;
}
// Saving Employees Name and Password
void Employee::SaveData(ofstream& OutputEmployee)
{
OutputEmployee << UserName << ",";
OutputEmployee << Password << endl;
}
// This will validate the name and password of the employee
bool Employee::CheckCredentials(string name, string pass)
{
return (name == UserName && Password == pass);
}
//destructor
Employee::~Employee()
{
}
// ============================================ TARRIF ============================================
class Tarrif
{
friend class LESCO;
friend class Bill;
private:
int RegularUnitPrice[4];
int PeakHourUnit_Price[4];
int Percentage_Tax_Domestic;
int Percentage_Tax_Commercial;
int Fixed_Charges_Domestic;
int Fixed_Charges_Commercial;
public:
Tarrif() // Constructor
{
for (int i = 0; i < 4; i++)
{
RegularUnitPrice[i] = 0;
PeakHourUnit_Price[i] = 0;
}
Percentage_Tax_Domestic = 0;
Percentage_Tax_Commercial = 0;
Fixed_Charges_Domestic = 0;
Fixed_Charges_Commercial = 0;
}
// This will load the file (TariffTaxInfo.txt) that contains the taxs information
bool LoadTarrifFile()
{
string temp;
ifstream Tariff("TarrifTaxInfo.txt");
if (Tariff)
{
for (int i = 0; i < 4; i++)
{
getline(Tariff, temp, ',');
getline(Tariff, temp, ',');
RegularUnitPrice[i] = stoi(temp);
getline(Tariff, temp, ',');
if (temp == "")
{
PeakHourUnit_Price[i] = 0;
}
else
PeakHourUnit_Price[i] = stoi(temp);
if (i == 0 || i == 2)
{
getline(Tariff, temp, ',');
Percentage_Tax_Domestic = stoi(temp);
getline(Tariff, temp, '\n');
Fixed_Charges_Domestic = stoi(temp);
}
if (i == 1 || i == 3)
{
getline(Tariff, temp, ',');
Percentage_Tax_Commercial = stoi(temp);
getline(Tariff, temp, '\n');
Fixed_Charges_Commercial = stoi(temp);
}
}
return 1;
}
else //If file not loaded
{
cout << endl << "Sorry Tariff File couldn't be open " << endl;
return 0;
}
}
// This will change the taxes percentage if required (by Lesco Employees )
void UpdateTarrifFile()
{
system("cls");
int entered_value = 0;
cout << "Enter 1- To change Tax Percentage for Domestic Customers\n"
<< "Enter 2- To change Tax Percentage for Commercial Customers\n"
<< "Enter 3- To change Fixed Charges for Domestic Customers\n"
<< "Enter 4- To change Fixed Charges for Commercial Customers\n"
<< "Enter 5- To change Regular Unit Price\n"
<< "Enter 6- To change Peak Hour Unit Price\n\n\n";
cin >> entered_value;
if (entered_value == 1)
{
cout << "Enter Tax Percentage for Domestic Customers";
cin >> Percentage_Tax_Domestic;
}
if (entered_value == 2)
{
cout << "Enter Tax Percentage for Commercial Customers";
cin >> Percentage_Tax_Commercial;
}
if (entered_value == 3)
{
cout << "Enter Fixed Charges for Domestic Customers";
cin >> Fixed_Charges_Domestic;
}
if (entered_value == 4)
{
cout << "Enter Fixed Charges for Commercial Customers";
cin >> Fixed_Charges_Commercial;
}
system("cls");
if (entered_value == 5)
{
int count;
cout << "============Regular Unit Price ===============\n\n";
cout << "Enter 1- Phase 1 and Domestic\n "
<< "Enter 2- Phase 1 and Commercial\n"
<< "Enter 3- Phase 3 and Domestic\n"
<< "Enter 4- Phase 3 and Commercial\n\n";
cin >> count;
if (count == 1)
{
cout << "Enter Regular Unit Price for Phase 1 Domestic Customers\n";
cin >> RegularUnitPrice[0];
}
if (count == 2)
{
cout << "Enter Regular Unit Price for Phase 1 Commercial Customers\n";
cin >> RegularUnitPrice[1];
}
if (count == 3)
{
cout << "Enter Regular Unit Price for Phase 3 Domestic Customers\n";
cin >> RegularUnitPrice[2];
}
if (count == 4)
{
cout << "Enter Regular Unit Price for Phase 3 Commercial Customers\n";
cin >> RegularUnitPrice[3];
}
}
if (entered_value == 6)
{
int count;
cout << "============Peak Hour Unit ===============\n\n";
cout << "Enter 1 Phase 3 Domestic \n"
<< "Enter 2 Phase 3 Commercial \n\n";
cin >> count;
if (count == 1)
{
cout << "Enter Peak Hour Unit for Phase 3 Domestic\n ";
cin >> PeakHourUnit_Price[2];
}
if (count == 2)
{
cout << "Enter Peak Hour Unit for Phase 3 Commercial\n ";
cin >> PeakHourUnit_Price[3];
}
}
InputUpdateTarrif();
}
void InputUpdateTarrif() // This file contains the taxes related to phases(1 phase or 3 phase)
{ // and commercial or domestic
ofstream Update("TarrifTaxInfo.txt");
for (int i = 0; i < 4; i++)
{
if (i == 0)
{
Update << "1Phase, "
<< RegularUnitPrice[i] << ","
<< PeakHourUnit_Price[i] << ","
<< Percentage_Tax_Domestic << ","
<< Fixed_Charges_Domestic << endl;
}
if (i == 1)
{
Update << "1Phase, "
<< RegularUnitPrice[i] << ","
<< PeakHourUnit_Price[i] << ","
<< Percentage_Tax_Commercial << ","
<< Fixed_Charges_Commercial << endl;
}
if (i == 2)
{
Update << "3Phase, "
<< RegularUnitPrice[i] << ","
<< PeakHourUnit_Price[i] << ","
<< Percentage_Tax_Domestic << ","
<< Fixed_Charges_Domestic << endl;
}
if (i == 3)
{
Update << "3Phase, "
<< RegularUnitPrice[i] << ","
<< PeakHourUnit_Price[i] << ","
<< Percentage_Tax_Commercial << ","
<< Fixed_Charges_Commercial << endl;
}
}
}
};
// ============================================ BILL ============================================
class Bill
{
Costumer *Consumer;
Tarrif *TarrifFile;
int CostumerId;
int BillMonth;
int MeterReadingPeak;
int MeterReadingReg;
string IssueDate;
int ElectricityCost;
int SalesTax;
int FixedCharges;
int TotalBill;
string CurrentMeterReading;
string DueDate;
bool billPaidStatus;
string BillPayementDate;
public:
Bill();
int GetId();
int GetMonth();
int getMeterReadingPeak();
int getMeterReadingRegulaer();
void SetConsumer(Costumer*);
int CalculationOfBill(int, int, int, int, int, int);
void GenerateBill(int, int, int, int, int);
int calculateBillPhase1Domestic(int, int, int, int);
int calculateBillPhase3Domestic(int, int, int, int, int, int);
int calculateBillPhase1Commercial(int, int, int, int);
int calculateBillPhase3Commercial(int, int, int, int, int, int);
void LoadDataFromFile(ifstream&);
void SaveBillInFile(ofstream &);
void ChangeBillStatus();
bool GetBillStatus() ;
void ShowBill();
string GetDate();
~Bill();
};
Bill::Bill() // Constructor
{
Consumer=0;
TarrifFile=0;
CostumerId = 0;
BillMonth = 0;
MeterReadingPeak = 0;
MeterReadingReg = 0;
IssueDate = "";
ElectricityCost = 0;
SalesTax = 0;
FixedCharges = 0;
TotalBill = 0;
DueDate = "";
CurrentMeterReading = "";
billPaidStatus = 0;
BillPayementDate = "";
}
int Bill::GetId()
{
return CostumerId;
}
int Bill::GetMonth()
{
return BillMonth;
}
string Bill::GetDate()
{
return IssueDate;
}
// This will take data(customer ID, Billing Month ,Meter Reading Peak etc) from file "BillInfo.txt"
void Bill::LoadDataFromFile(ifstream& inputBill)
{
char ign;
inputBill >> CostumerId;
inputBill >> ign;
inputBill >> BillMonth;
inputBill >> ign;
inputBill >> MeterReadingPeak;
inputBill >> ign;
inputBill >> MeterReadingReg;
inputBill >> ign;
getline(inputBill, IssueDate, ',');
inputBill >> ElectricityCost;
inputBill >> ign;
inputBill >> SalesTax;
inputBill >> ign;
inputBill >> FixedCharges;
inputBill >> ign;
inputBill >> TotalBill;
inputBill >> ign;
getline(inputBill, DueDate, ',');
inputBill >> billPaidStatus;
inputBill >> ign;
getline(inputBill, BillPayementDate, '\n');
}
void Bill::SetConsumer(Costumer* costumer)
{
Consumer = costumer;
}
// This function generates the bill by taking input from the customer
void Bill::GenerateBill(int id, int MeterType, int CostumerType, int regUnit, int PeakUnit)
{
TarrifFile = new Tarrif;
TarrifFile->LoadTarrifFile();
//regunit previous meter reading
CostumerId = id;
int Year, Month, Day;
string tempYear, tempMonth, tempDay;
cout << "Enter Billing Month: ";cin >> BillMonth;
if (MeterType == 3)
{
cout << "Enter Meter Reading PEAK : ";
cin >> MeterReadingPeak;
if(MeterReadingPeak<PeakUnit)
{
cout<<"Meter reading Peak cannot be Less than previous Month's reading!"<<endl;
return;
}
}
cout << "Enter Meter Reading REGULAR : ";
cin >> MeterReadingReg;
if(MeterReadingReg<regUnit)
{
cout<<"Meter reading regular cannot be Less than previous Month's reading!"<<endl;
return;
}
cout << "\nEnter Issue Date of Bill in the format YYYY MM DD :\t";
cin >> Year >> Month >> Day;
if(BillMonth!=Month)
{
cerr<<"Bill Cannot be Generated As months are not Equal"<<endl;
return ;
}
Helper::CheckDateValidity(Year, Month, Day);
tempYear = to_string(Year);
tempMonth = to_string(Month);
tempDay = to_string(Day);
if (Month < 10 && Day < 10)
{
IssueDate = tempYear + '0' + tempMonth + '0' + tempDay;
}
else
IssueDate = tempYear + tempMonth + tempDay;
if (Month < 10 && Day>9)
IssueDate = tempYear + '0' + tempMonth + tempDay;
if (Day < 10 && Month>9)
IssueDate = tempYear + tempMonth + '0' + tempDay;
cout << "\nEnter Due Date of Bill in the format YYYY MM DD :\t";
cin >> Year >> Month >> Day;
Helper::CheckDateValidity(Year, Month, Day);
tempYear = to_string(Year);
tempMonth = to_string(Month);
tempDay = to_string(Day);
if (Month < 10 && Day < 10)
{
DueDate = tempYear + '0' + tempMonth + '0' + tempDay;
}
else
DueDate = tempYear + tempMonth + tempDay;
if (Month < 10 && Day>9)
DueDate = tempYear + '0' + tempMonth + tempDay;
if (Day < 10 && Month>9)
DueDate = tempYear + tempMonth + '0' + tempDay;
if (MeterType == 1 && CostumerType == 2)//phase1 and domestic
calculateBillPhase1Domestic(regUnit, TarrifFile->Percentage_Tax_Domestic, TarrifFile->RegularUnitPrice[0], TarrifFile->Fixed_Charges_Domestic);
if (MeterType == 3 && CostumerType == 2) //phase3 and domestic
calculateBillPhase3Domestic(regUnit, PeakUnit, TarrifFile->Percentage_Tax_Domestic, TarrifFile->RegularUnitPrice[2], TarrifFile->Fixed_Charges_Domestic, TarrifFile->PeakHourUnit_Price[2]);
if (MeterType == 1 && CostumerType == 1) //phase1 and commercial
calculateBillPhase1Commercial(regUnit, TarrifFile->Percentage_Tax_Commercial, TarrifFile->RegularUnitPrice[1], TarrifFile->Fixed_Charges_Commercial);
if (MeterType == 3 && CostumerType == 1) //phase3 and commercial
calculateBillPhase3Commercial(regUnit, PeakUnit, TarrifFile->Percentage_Tax_Commercial, TarrifFile->RegularUnitPrice[3], TarrifFile->Fixed_Charges_Commercial, TarrifFile->PeakHourUnit_Price[3]);
cout << "Bill Generated Successfully!" << endl;
delete TarrifFile;
}
// Calculation of Bill for Phase1 (Domestic) Consumers
int Bill::calculateBillPhase1Domestic(int regUnit, int taxdomestic, int regUnitPrice, int fixedChargeDomestic)
{
int cost;
cost = MeterReadingReg-regUnit;
cost = cost * regUnitPrice;
ElectricityCost = cost;
SalesTax = taxdomestic;
cost = (cost*taxdomestic) / 100;
FixedCharges = fixedChargeDomestic;
cost = cost + fixedChargeDomestic;
TotalBill = cost;
return TotalBill;
}
// Calculation of Bill for Phase3 (Domestic) Consumers
int Bill::calculateBillPhase3Domestic(int regUnit, int PeakUnit, int taxdomestic, int regUnitPrice, int fixedChargeDomestic, int PeakUnitPrice)
{
int cost, peakCost;
cost = MeterReadingReg-regUnit;
peakCost = MeterReadingPeak-PeakUnit;
cost = cost * regUnitPrice;
peakCost = peakCost * PeakUnitPrice;
cost = cost + peakCost;
ElectricityCost = cost;
cost = (cost*taxdomestic) / 100;
SalesTax = taxdomestic;
cost = cost + fixedChargeDomestic;
FixedCharges = fixedChargeDomestic;
TotalBill = cost;
return TotalBill;
}
// Calculation of Bill for Phase1 (Commercial) Consumers
int Bill::calculateBillPhase1Commercial(int regUnit, int taxCommercial, int regUnitPriceForCommercial, int fixedChargeCommercial)
{
int cost;
cost = MeterReadingReg-regUnit;
cost = cost * regUnitPriceForCommercial;
ElectricityCost = cost;
cost = (cost*taxCommercial) / 100;
SalesTax = taxCommercial;
cost += fixedChargeCommercial;
FixedCharges = fixedChargeCommercial;
TotalBill = cost;
return TotalBill;
}
// Calculation of Bill for Phase3 (Commercial) Consumers
int Bill::calculateBillPhase3Commercial(int regUnit, int PeakUnit, int taxCommercial, int regUnitPrice, int fixedChargeCommercial, int PeakUnitPrice)
{
int cost, peakCost;
cost = MeterReadingReg-regUnit;
peakCost = MeterReadingPeak-PeakUnit;
cost = cost * regUnitPrice;
peakCost = peakCost * PeakUnitPrice;
cost = peakCost + cost;
ElectricityCost = cost;
cost = (cost*taxCommercial) / 100;
SalesTax = taxCommercial;
cost = cost + fixedChargeCommercial;
FixedCharges = fixedChargeCommercial;
TotalBill = cost;
return TotalBill;
}
int Bill::CalculationOfBill(int regUnit, int merterreading, int peakUnit, int peakreading, int meterType, int CostumType)
{
int TotalAmount = 0;
TarrifFile = new Tarrif;
if (TarrifFile->LoadTarrifFile())
{
MeterReadingReg = merterreading;
MeterReadingPeak = peakreading;
if (MeterReadingReg < regUnit)
{
cout << "Meter Reading Regular Cannot be smaller than Previous meter Reading!" << endl;
return 0;
}
if (MeterReadingPeak < peakUnit)
{
cout << "Meter Reading Peak Cannot be smaller than Previous meter Reading!" << endl;
return 0;
}
if (meterType == 1 && CostumType == 2)//phase1 and domestic
calculateBillPhase1Domestic(regUnit, TarrifFile->Percentage_Tax_Domestic, TarrifFile->RegularUnitPrice[0], TarrifFile->Fixed_Charges_Domestic);
if (meterType == 3 && CostumType == 2) //phase3 and domestic
TotalAmount = calculateBillPhase3Domestic(regUnit, peakUnit, TarrifFile->Percentage_Tax_Domestic, TarrifFile->RegularUnitPrice[2], TarrifFile->Fixed_Charges_Domestic, TarrifFile->PeakHourUnit_Price[2]);
if (meterType == 1 && CostumType == 1) //phase1 and commercial
TotalAmount = calculateBillPhase1Commercial(regUnit, TarrifFile->Percentage_Tax_Commercial, TarrifFile->RegularUnitPrice[1], TarrifFile->Fixed_Charges_Commercial);
if (meterType == 3 && CostumType == 1) //phase3 and commercial
TotalAmount = calculateBillPhase3Commercial(regUnit, peakUnit, TarrifFile->Percentage_Tax_Commercial, TarrifFile->RegularUnitPrice[3], TarrifFile->Fixed_Charges_Commercial, TarrifFile->PeakHourUnit_Price[3]);
return TotalAmount;
}
else
{
cerr << "Tarrif File is Not Found!\nBill cannot Be calculated!" << endl;
return 0;
}
delete TarrifFile;
}
// This will change the bill status from unpaid to paid
void Bill::ChangeBillStatus()
{
billPaidStatus = 1;
}
// Store bill in a file
void Bill::SaveBillInFile(ofstream & OutputBill)
{
OutputBill << CostumerId << ",";
OutputBill << BillMonth << ",";
OutputBill << MeterReadingPeak << ",";
OutputBill << MeterReadingReg << ",";
OutputBill << IssueDate << ",";
OutputBill << ElectricityCost << ",";
OutputBill << SalesTax << ",";
OutputBill << FixedCharges << ",";
OutputBill << TotalBill << ",";
OutputBill << DueDate << ",";
OutputBill << billPaidStatus << ",";
OutputBill << BillPayementDate << endl;
}
// Shows the Customer Bill
void Bill::ShowBill()
{
cout << " Cost of Electricity : " << ElectricityCost << endl << endl;
cout << "Tax percentage :" << SalesTax << endl << endl;
cout << "Fixed Charges : " << FixedCharges << endl << endl;
cout << "Total amount due :" << TotalBill << endl << endl;
cout << "Due Date :" << DueDate << endl << endl;
cout << "Billing month: " << BillMonth << endl << endl;
if (billPaidStatus)
cout << "paid Bill Status: " << "Paid" << endl;
else
cout << "paid Bill Status: " << "UnPaid" << endl;
}
bool Bill::GetBillStatus()
{
return billPaidStatus;
}
int Bill::getMeterReadingPeak()
{
return MeterReadingPeak;
}
int Bill::getMeterReadingRegulaer()
{
return MeterReadingReg;
}
Bill::~Bill()
{
if(TarrifFile)
delete TarrifFile;
}
// ============================================ CUSTOMER ============================================
class Costumer
{
string UserName;
int CostumerId;
string DateOfBirth;
string PhoneNumber;
string Address;
int CostumerType;
int MeterType;
string ConnectionDate;
int RegUnits;
int PeakHourUnits;
Bill **CurrentBill;
int NoofBill;
public:
Costumer();
int GetId()
{
return CostumerId;
}
int GetMeterType()
{
return MeterType;
}
int GetCostumerType()
{
return CostumerType;
}
int GetRegUnits()
{
return RegUnits;
}
int GetPeakHourUnits()
{
return PeakHourUnits;
}
string GetPhoneNo()
{
return PhoneNumber;
}
string GetUsername()
{
return UserName;
}
string Getaddress()
{
return Address;
}
string GetdateofBirth()
{
return DateOfBirth;
}
void SetRegUnits(int i)
{
RegUnits = i;
}
void SetPeakHourUnits(int i)
{
PeakHourUnits = i;
}
bool UserExist(int id, string date, int metertype, int);
void LoadDataFromFile(ifstream&);
void InputCostumerData();
void SaveData(ofstream&);
bool CheckCredentials(int, string);
void SetBill(Bill*);
void ViewBill();
void UpdateInfo();
bool CheckId(int );
~Costumer();
};
Costumer::Costumer() // Constructor
{
UserName = "";
CostumerId = 0;
PhoneNumber = "";
Address = "";
DateOfBirth = "";
ConnectionDate = "";
CostumerType = 0;
MeterType = 0;
RegUnits = 0;
PeakHourUnits = NULL;
CurrentBill = 0;
NoofBill = 0;
}
// Load data from file name "CustomerInfo.txt"
void Costumer::LoadDataFromFile(ifstream& InputCostumer)
{
string y, m, d;
char ign;
InputCostumer >> CostumerId;
InputCostumer >> ign;
getline(InputCostumer, DateOfBirth, ',');
getline(InputCostumer, UserName, ',');
getline(InputCostumer, Address, ',');
getline(InputCostumer, PhoneNumber, ',');
InputCostumer >> CostumerType;
InputCostumer >> ign;
InputCostumer >> MeterType;
InputCostumer >> ign;
getline(InputCostumer, ConnectionDate, ',');
InputCostumer >> RegUnits;
InputCostumer >> ign;
InputCostumer >> PeakHourUnits;
}
// Takes Data(Name ,Address , Date of Birth) from the Customer
void Costumer::InputCostumerData()
{
int Year, Month, Day, Valid = 0;
string tempYear, tempMonth, tempDay;
srand(time(0));
CostumerId = rand() % 9000 + 1000;
cout << "Enter Costumer Name:\t";
getline(cin, UserName);
cout << "\nEnter Costumer Phone number:\t";
getline(cin, PhoneNumber);
cout << "\nEnter Costumer Address:\t";
getline(cin, Address);
cout << "\nEnter Costumer date of birth in the format YYYYMMDD :\t";
cin >> Year >> Month >> Day;
Helper::CheckDateValidity(Year, Month, Day); // check if the entered date is correct or not
tempYear = to_string(Year);
tempMonth = to_string(Month);
tempDay = to_string(Day);
if (Month < 10 && Day < 10)
{
DateOfBirth = tempYear + '0' + tempMonth + '0' + tempDay;
}
else
DateOfBirth = tempYear + tempMonth + tempDay;
if (Month < 10 && Day>9)
DateOfBirth = tempYear + '0' + tempMonth + tempDay;
if (Day < 10 && Month>9)
DateOfBirth = tempYear + tempMonth + '0' + tempDay;
cout << "\nEnter Your Customer type (Enter 1 for Commercial Or Enter 2 For Domestic ):\t";
cin >> CostumerType;
int count = 0;
cout << "\nEnter Your Meter Type ( 1 for Single phase , 3 for Three Phase) : \t";
cin >> MeterType;
while (count < 2 && Valid != true)
{
if (MeterType == 1 || MeterType == 3)
{
Valid = true;
break;
}
else
{
cout << "Incorrect meter type! \nenter 1 for single phase meter and 3 for three phase meter\n";
cin >> MeterType;
count++;
Valid = false;
}
}
if (Valid == true)
{
cout << "\nEnter Connection Date (YYYYMMDD):\t";
cin >> Year >> Month >> Day;
Helper::CheckDateValidity(Year, Month, Day); // Checks if the date entered is valid or not
tempYear = to_string(Year);
tempMonth = to_string(Month);
tempDay = to_string(Day);
if (Month < 10 && Day < 10)
{
ConnectionDate = tempYear + '0' + tempMonth + '0' + tempDay;
}
else
ConnectionDate = tempYear + tempMonth + tempDay;
if (Month < 10 && Day>9)
ConnectionDate = tempYear + '0' + tempMonth + tempDay;
if (Day < 10 && Month>9)
ConnectionDate = tempYear + tempMonth + '0' + tempDay;
if (MeterType == 1)
{
cout << "\nEnter Regular units consumed:\t";
cin >> RegUnits;
cout << endl;
}
else
if (MeterType == 3)
{
cout << "\nEnter Regular units consumed:\t";
cin >> RegUnits;
cout << endl;
cout << "\nEnter Peak Hour units consumed:\t";
cin >> PeakHourUnits;
cout << endl;
}
cout << "You are registered sucessfully\n";
cout << "Your customer id is " << " \"" << CostumerId << "\" \n";
}
else
{
cout << "Sorry you cannot be registered. Try again later.Thankyou!";
}
}
void Costumer::SaveData(ofstream& outputCostumer)
{
outputCostumer << CostumerId << ",";
outputCostumer << DateOfBirth << ",";
outputCostumer << UserName << ",";
outputCostumer << Address << " ,";
outputCostumer << PhoneNumber << ",";
outputCostumer << CostumerType << ",";
outputCostumer << MeterType << ",";
outputCostumer << ConnectionDate << ",";
outputCostumer << RegUnits << "," << PeakHourUnits << endl;
}
// This will enable the user to see his Current bill
void Costumer::ViewBill()
{
system("cls");
cout << "\n\t\t ==============CUSTOMER'S BILL=============" << endl<<endl;
cout << "Cotumer Id: " << CostumerId << endl << endl;
cout << "Costumer UserName: " << UserName << endl << endl;
cout << "Adress :" << Address << endl << endl;
cout << "Phone Number: " << PhoneNumber << endl << endl;
if (CostumerType == 1)
cout << "Costumer Type: Commercial Costumer" << endl << endl;
else
cout << "Costumer Type: Domestic Costumer" << endl << endl;
if (MeterType == 1)
cout << "Meter Type: Single Phase Meter" << endl << endl;
else
cout << "MeterType: 3Phase Phase Meter" << endl << endl;
CurrentBill[NoofBill - 1]->ShowBill();
return;
}
// check validity of Customer(id , date ,meter type ) by comparing from File Data
bool Costumer::UserExist(int id, string date, int metertype, int CostumType)
{
return (id == CostumerId && date == DateOfBirth && MeterType == metertype && CostumerType == CostumType);
}
void Costumer::UpdateInfo()
{
int Option;
cout << "Enter 1 to Update All the enteries belonging to this Customer id\n"
<< "Enter 2 to Update Specific information of this Customer\n";
cin >> Option;
if (Option == 1)
{
cin.ignore();
InputCostumerData();
}
if (Option == 2)
{
int choice;
system("cls");
cout << "Press 1 to Update UserName \n"
<< "Press 2 to Update Phone Number\n"
<< " Press 3 to update address\n"
<< "Press 4 to update DateOfBirth\n"
<< "Press 5 to Update Customer Type\n"
<< "Press 6 to Update Meter Type\n"
<< "Press 7 to Update Regular units consumed\n"
<< "Press 8 to Update Units consumed in Peak hour\n";
// Customer will enter the choice number from the menu according to the task to be performed
cin >> choice;
if (choice == 1)
{
cin.ignore();
cout << "Enter new UserName \n";
cin >> UserName;
}
if (choice == 2)
{
cin.ignore();
cout << "Enter new phone Number \n";
getline(cin, PhoneNumber);
}
if (choice == 3)
{
cin.ignore();
cout << "Enter new Address \n";
getline(cin, Address);
}
if (choice == 4)
{
cin.ignore();
cout << "Enter new Date of Birth of format(YYYY MM DD) \n";
int Year, Month, Day;
cin >> Year >> Month >> Day;
Helper::CheckDateValidity(Year, Month, Day);
string tempYear = to_string(Year);
string tempMonth = to_string(Month);
string tempDay = to_string(Day);
if (Month < 10 && Day < 10)
{
DateOfBirth = tempYear + '0' + tempMonth + '0' + tempDay;
}
else
DateOfBirth = tempYear + tempMonth + tempDay;
if (Month < 10 && Day>9)
DateOfBirth = tempYear + '0' + tempMonth + tempDay;
if (Day < 10 && Month>9)
DateOfBirth = tempYear + tempMonth + '0' + tempDay;
}
if (choice == 5)
{
cin.ignore();
cout << "Enter new costumer type \n";
cin >> CostumerType;
}
if (choice == 6)
{
cin.ignore();
cout << "Enter new MeterType \n";
cin >> MeterType;
}
if (choice == 7)
{
cin.ignore();
cout << "Enter new regular Unit Consumed \n";
cin >> RegUnits;
}