Utilities
Programming Assignment # 1
By
Timothy Goodwin
CSC2100 Introduction to Problem Solving and Computer Programming
Spring 2011
Date Submitted: February 18, 2011
Test Cases:
Test Case Number Input Values Expected Output
1 500,500,r 25,53,26.5,104.5
2 500,500,c 40,76.5,53.55,170.05
3 500,500,i 100,50,35,185
Appendix A:
Test Case Input Values Date & Time Actual Output Result
Number
1 500,500,r 2/16 18:55 25,53,26.5,104.5 Pass
2 500,500,c 2/16 18:56 25,53,26.5,104.5 Fail
3 500,500,i 2/16 18:56 25,53,26.5,104.5 Fail
4 500,500,i 2/18 9:20 100,50,35,185 Pass
Appendix B:
//Timothy Goodwin Utilities Program Program Assignment 1 Csc 2100 Spring 2011
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
//Integer variables for range/if statement for cin account number
int min;
min = 1000;
int max;
max = 9999;
int number;
//electric measurement units
double kwh;
//Water measurement units
double units;
//kilowatt surcharge
double kwhsur;
//sewer charge
double scharge;
//water charge
double wcharge;
//electric charge
double echarge;
//total charges
double tcharges;
//variable to change char category into a string assignment with full names I.E. Residential, Commercial,and
Industrial
string cat;
//cat assignment names
string Residential,Commercial,Industrial;
//category is input r, R, c, C, i, I
char category;
//category possibilities
char r,R,c,C,i,I;
//cin number is account number entry
cout << "Please enter a 4 digit account number and press <Enter>" << endl;
cin>> number;
//data type for account name cin name is account name entry
char name [26];
cout <<"Please enter an account name <= 25 characters, and press <Enter>. Any characters in excess of 25 will be
discarded" << endl;
cin >> setw (25) >> name;
cout <<"Please enter Kwh electric consumption" << endl;
cin >> kwh;
cout << "please enter water consumption" << endl;
cin >> units;
cout << "enter a service category: enter r (or R) for residential, c (or C) for commercial, or I (or I) for industrial and
the <Enter>" << endl;
//entry of category and if statement to make sure r is chosen if input is not r,R,c,C,i,I
cin >> category;
if (category != 'r' && category != 'R' && category != 'c' && category != 'C' && category != 'i' && category !=
'I')
{
category = 'r';
if (category == 'r' || category == 'R')
//kwh if statement to calculate electric charge
if (kwh <= 500)
echarge = (kwh * .05);
else
echarge = (kwh - 500) * (.025) + (500 * .05);
if (kwh < 0)
echarge = (100 * .05);
else if (echarge < 2.00)
echarge = 2.00;
if (kwh >1000)
kwhsur= 5.00;
else
kwhsur= 0;
//if statement to calculate water charge
if (units <= 30)
wcharge = (units * .20);
else if (units > 30)
wcharge = (units - 30) * .10 + (30 * .20);
if (units < 0)
wcharge = (25 * .20);
else if (wcharge < 2.00)
wcharge = 2.00;
//sewer charge
scharge = (wcharge * .5);
//total charges
tcharges = (echarge + kwhsur + wcharge + scharge);
//assignment of Residential to category r or R
cat = "Residential";
else if( category == 'c' || category == 'C')
//kwh if statement to calculate electric charge
if (kwh <= 600)
echarge = (kwh * .08);
else if
(kwh > 600)
echarge = (kwh - 600) * (.050) + (600 * .08);
if (kwh < 0)
echarge = (100 * .08);
else if (echarge < 10.00)
echarge = 10.00;
if (kwh >1500)
{
kwhsur= 10.00;
else
kwhsur= 0;
//if statement to calculate water charge
if (units <= 30)
wcharge = (units * .20);
else if (units > 30)
wcharge = (units - 30) * .15 + (30 * .20);
if (units < 0)
wcharge = (25 * .20);
else if (wcharge < 2.00)
wcharge = 2.00;
//sewer charge
scharge = (wcharge * .7);
//total charges
tcharges = (echarge + kwhsur + wcharge + scharge);
//assignment of Commercial to category c or C
cat = "Commercial";
else if( category == 'i' || category == 'I')
//kwh if statement to calculate electric charge
{
if (kwh <= 2500)
echarge = (kwh * .06);
else if
(kwh > 2500)
echarge = (kwh - 2500) * (.015) + (2500 * .06);
if (kwh < 0)
echarge = (100 * .06);
else if (echarge < 100.00)
echarge = 100.00;
if (kwh >1500)
kwhsur= 10.00;
else
kwhsur= 0;
//if statement to calculate water charge
if (units <= 5000)
wcharge = (units * .10);
else if (units > 5000)
wcharge = (units - 5000) * .02 + (5000 * .10);
if (units < 0)
wcharge = (25 * .10);
else if (wcharge < 50.00)
wcharge = 50.00;
}
//sewer charge
scharge = (wcharge * .7);
//total charges
tcharges = (echarge + kwhsur + wcharge + scharge);
assignment of Industrial to category i or I
cat = "Industrial";
cout << setw (20) << "
*********************************************************************************************
************************" << endl << endl << endl;
cout << setw (78) << "COOKEVILLE UTILITY DISTRICT" << endl << endl << endl;
cout << setw (20) << "
*********************************************************************************************
************************" << endl << endl << endl;
if (number <= max && number >=min)
//account number output
cout << "Account Number: " << number << endl;
else
cout << "the number was not in the specified range" << endl;
//account name output
cout << "Account Name: "<< name << endl << endl << endl << endl;
//service category output
cout << "Service Category:" << cat << endl;
//Electric Consumption and charge output
cout << "Electric Consumption = " << kwh << setw (93) << "Electric Charge: $" << echarge << setw (85) << endl;
//Electric surcharge
cout << setw (120) << "Surcharge $" << kwhsur << endl << endl << endl;
//Water Consumption and charge output
cout <<"Water Consumption:" << units << setw (99) << " Water Charge: $" << wcharge << endl;
//Sewer charge
cout << setw (120) <<" Sewer Charge: $" << scharge << endl;
//Total charges
cout << setw (120) <<"Total Charge: $" << tcharges << endl;
cout << setw (20) << " ************************************** Done Processing Utilitly Bill
************************************************" << endl;
return 0;