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
|
>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
//fucntion prototype
string get_cust_ID();
double get_cust_kwh();
double calc_charges(double uc);
void display_cust_data(double total, double amt, double uc, char response, string customerID);
void display_final_data();
int main()
{
double totUC = 0.0, totAMT = 0.0, totCust = 0.0;
int countUC, countAMT, countCust;
string custID;
double uc, amt, total,sum,cust;
char response;
cout << fixed << setprecision(2);
countCust = 0;
cout << "Would you like to add a customer?" << endl;
cin >> response;
while (response == 'Y' || response == 'y');
{
custID = get_cust_ID();
totCust += cust;
++countCust;
uc = get_cust_kwh();
totUC += total;
++countUC;
calc_charges(uc);
totAMT += sum;
++countAMT;
display_cust_data(total, amt, uc, response, custID);
}
system("CLS");
display_final_data(totAMT, totCust,totUC);
return 0;
}
string get_cust_ID(){
string custID;
cout << "Enter 3 digit ID: ";
cin >> custID;
return custID;
}
double get_cust_kwh(){
double uc;
//Input the units consumed
cout << "Enter the KWH consumed by the consumer" << endl;
cin >> uc;
return uc;
}
double calc_charges(double uc){
double amt;
if (uc >= 0 && uc <= 300)
amt = uc * .12;
else
{
if (uc > 300 && uc <= 600)
amt = ((300 * .12) + (uc - 300))*.09;
else
if (uc > 600 && uc <= 1000)
amt = (300 * .12 + 300 * .09) + (uc - 600) * .06;
else
amt = (300 * .12 + 300 * .09 + 400 * .06) + (uc - 1000)* .04;
}
return amt;
}
void display_cust_data(double total,double amt,double uc,char response,string customerID){
cout << setw(20) << left << "Customer ID" << setw(10) << left << "KWHours" << setw(4) << left << "Charge($)" << endl;
cout << setw(20) << left << customerID << setw(10) << left << uc << setw(4) << left << "$" << amt << endl;
cout << endl;
cout << "Would you like to add a customer?(Y/N)" << endl;
cin >> response;
}
void display_final_data(double totCust, double totUC, double totAMT){
double average = 0.00;
double totCust,totUC,totAMT;
average = totAMT / totCust;
//print the bill
cout << setw(6) << right << "CUSTOMER READ OUT" << endl;
cout << "---------------------------" << endl;
cout << setw(6) << left << " Customer Count:" << endl;
cout << setw(6) << left << totCust << endl;
cout << endl;
cout << setw(6) << left << "Total KWHours" << endl;
cout << setw(6) << left << totUC << endl;
cout << endl;
cout << setw(6) << left << "Total Charges" << endl;
cout << setw(5) << left << "$" << setw(6) << left << totAMT << endl;
cout << "---------------------------" << endl;
cout << setw(6) << left << "Average" << endl;
cout << setw(6) << left << average << endl;
}
<
|