This is an C++ project. Your job at the Lost Angels Department of Water and Powe
ID: 3662744 • Letter: T
Question
This is an C++ project.
Your job at the Lost Angels Department of Water and Power is to produce the electric bill for residential and business customers given their power usage. The program you write must accept as input the customer's name, the energy used in kilowatt hours and the customer's type (either Residential or Business).
Here is an example of a dialog with the program (user input is in boldface):
The power readings are floating point values in units of kilowatt hours (kWh). In the example above, Howard Stahl used 13.5 kWh for the billing period.
Regardless of the amount of power used, all customers will be charged a monthly service charge. Residential customers are billed a $14.95 service charge. Business customers are billed a $19.95 service charge. Power costs vary for Residential and Business customers with Business customers paying slightly more for the same level of usage. In addition, power costs are charged based on tiered rates with lower tiers costing less which tries to incentivize customers to not waste power. The first tier rateapplies to the first 10 kilowatt hours used in a billing period. The second tier rate applies to the next 10 kilowatt hours used in a billing period. The third tier rate applies to all the power used beyond the second tier rate.
For Residential customers, the first tier rate is $4.50 per kWh. The second tier rate is $9.00 per kWh. The third tier rate is $15.00 per kWh.
For Business customers, the first tier rate is $7.50 per kWh. The second tier rate is $15.00 per kWh. The third tier rate is $20.00 per kWh.
Since Howard is a Residential customer and used 13.5 kWh, he's billed a service charge of $14.95 as well $4.50 per kWh for the first 10 kWh and then $9.00 per kWh for the remaining 3.5 kWh.
Here's another example:
Since Dee Dee Reese Cookies is a Business customer and used 13.5 kWh, they will be billed a service charge of $19.95 as well $7.50 per kWh for the first 10 kWh and then $15.00 per kWh for the remaining 3.5 kWh.
You can test your understanding of the rate schedule by experimenting with the water bill calculator we found at the Lost Angels Department of Water and Power website.
Your program must collect the information for one customer in the manner indicated by the examples, and then write to cout a line with three hyphens only (no spaces or other characters), followed by exactly one line in a format required below. Our grading tool will judge the correctness of your program by examining only the line following the line with three hyphens. That line you write must be in one of the following four forms; the text must be identical to what is shown, except that italicized items are replaced as appropriate:
If the power usage is negative:
The energy usage reading must be nonnegative.
If an empty string was provided for the customer name:
You must enter a customer name.
If the customer type is neither Business nor Residential:
The customer type is not valid.
If the input is valid and none of the preceding situations holds:
The bill for customer is $amount
In the last case, customer must be the customer name as entered, and amount must be the correct answer, shown as a number with at least one digit to the left and exactly two digits to the right of the decimal point. (See pp. 30-31 in the Savitch book.) The lines you write must not start with any spaces. If you are not a good speller or typist, or if English is not your first language, be especially careful about duplicating the messages exactly. Here are some foolish mistakes that may cause you to get no points for correctness on this project, no matter how much time you put into it:
Not writing to cout a line with exactly three hyphens in all cases.
Writing any spaces on the line that is supposed to have three hyphens.
Writing more than one line after the line with three hyphens. Don't, for example, add a gratuitous "Mandatory conservation restrictions are in effect."
Writing lines to cerr instead of cout.
Writing lines like these:
Your program must gather the customer's name, the power used and the customer's type in that order. However, if you detect an error in an item, you do not have to request or get the remaining items if you don't want to; just be sure you write to cout the line of three hyphens, the required message and nothing more after that. If instead you choose to gather all input first before checking for any errors, and you detect more than one error, then after writing the line of three hyphens, write only the error message for the earliest erroneous input item.
You will not write any loops in this program. This means that each time you run the program, it handles only one bill. It also means that in the case of bad input, you must not keep prompting the user until you get something acceptable; our grading tool will not recognize that you're doing that.
A string with no characters in it is the empty string. A string with at least one character in it is not the empty string, even if the only characters in it are things like spaces or tabs. Although realistically it would be silly to have a customer name consisting of seventeen spaces and nothing more, treat that as you would any other non-empty string: as a valid name. (Since you don't yet know how to check for that kind of situation anyway, we're not requiring you to.)
The one kind of input error your program does not have to deal with (because you don't yet know enough to know how to do this nicely) is the case of not finding an integer in the input where an integer is expected. We promise that our grading tool will not, for example, supply the text Howard or the number when your program requests a power usage amount.
The correctness of your program must not depend on undefined program behavior. Your program could not, for example, assume anything about n's value at the point indicated:
Explanation / Answer
// Here is the program
#include<iostream>
#include<string>
#include<stdio.h>
int main()
{
string name;
float energy_used, bill;
string cust_type;
float service_charge_residential, service_charge_business;
float first_tier_business, second_tier_business,third_tier_business,first_tier_res, second_tier_res,third_tier_res;
service_charge_residential=14.95;
service_charge_business=19.95;
first_tier_business=7.50;
second_tier_business=15.00;
third_tier_business=20;
first_tier_res=4.50;
second_tier_res=9.0;
third_tier_res=15.0;
cout << "Customer Name: ";
cin >> name;
if(name.length()<1)
{
cout <<"---" << endl;
cout<< "You must enter a customer name.";
exit(0);
}
cout << "Energy Used (in kilowatt hours): ";
cin >> energy_used;
if(energy_used < 0)
{
cout <<"---" << endl;
cout<< "The energy usage reading must be nonnegative.";
exit(0);
}
cout << " Customer Type: ";
cin >> cust_type;
if(cust_type!="residential" && cust_type!="Residential" && cust_type!="business" && cust_type!="Business")
{
cout <<"---" << endl;
cout<< "The customer type is not valid." << cust_type << cust_type.compare("Residential") ;
exit(0);
}
if(cust_type=="Residential" || cust_type=="residential")
{
bill=service_charge_residential;
if(energy_used <= 10)
bill=bill + energy_used*first_tier_res;
else if(energy_used > 10 && energy_used <= 20)
{
bill=bill + 10*first_tier_res;
bill=bill+ (energy_used-10)*second_tier_res;
}
else
{
bill=bill + 10*first_tier_res + 10*second_tier_res;
bill=bill+ (energy_used-20)*third_tier_res;
}
cout <<"---" << endl;
cout << "The bill for "<<name<<" is $"<< bill;
}
else if(cust_type=="Business" || cust_type=="business")
{
bill=service_charge_business;
if(energy_used <= 10)
bill=bill + energy_used*first_tier_business;
else if(energy_used > 10 && energy_used <= 20)
{
bill=bill + 10*first_tier_business;
bill=bill+ (energy_used-10)*second_tier_business;
}
else
{
bill=bill + 10*first_tier_business + 10*second_tier_business;
bill=bill+ (energy_used-20)*third_tier_business;
}
cout <<"---" << endl;
cout << "The bill for "<<name<<" is $"<< bill;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.