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
|
#include <iostream>
#include <iterator>
#include <map>
using namespace std;
int main()
{
//declaring variables
string TDU;
double usage;
double total_charge;
int run = 1;
//declare a map to store names of TDU and montly fixed costs in dollars
map<string, double> monthlycharges;
monthlycharges.insert(pair<string, double>("ONCOR", 3.42));
monthlycharges.insert(pair<string, double>("CENTERPOINT ENERGY", 5.47));
monthlycharges.insert(pair<string, double>("AEP TEXAS CENTRAL", 9.00));
monthlycharges.insert(pair<string, double>("AEP TEXAS NORTH", 10.53));
monthlycharges.insert(pair<string, double>("TEXAS - NEW MEXICO POWER", 7.85));
//declare a map to store names of TDU and usage costs in cents
map<string, double> kwhcharges;
kwhcharges.insert(pair<string, double>("ONCOR", 3.8447));
kwhcharges.insert(pair<string, double>("CENTERPOINT ENERGY", 4.03120));
kwhcharges.insert(pair<string, double>("AEP TEXAS CENTRAL", 4.84460));
kwhcharges.insert(pair<string, double>("AEP TEXAS NORTH", 4.01990));
kwhcharges.insert(pair<string, double>("TEXAS - NEW MEXICO POWER", 4.83210));
while (run == 1) {
cout << "Enter the name of TDU: " << endl;
std::getline(std::cin >> std::ws, TDU);
cout << "Enter the usage in kWh used: " << endl;
cin >> usage;
//declare iterator of maps
map<string, double>::iterator it_monthlycharges;
map<string, double>::iterator it_kwhcharges;
//use the find function of map to get the pointer to correct entry according to key 'TDU'
it_monthlycharges = monthlycharges.find(TDU);
it_kwhcharges = kwhcharges.find(TDU);
//calculate the charges
total_charge = it_monthlycharges->second + (it_kwhcharges->second * 0.01 * usage);
//print the final output
cout << "TDU Delivery charges for " << TDU << " : " << total_charge << endl;
cout << "Enter 1 to calculate bill for another month, 0 to exit" << endl;
cin >> run;
}
return 0;
}
| |