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
|
#include <iostream>
#include <iomanip>
using namespace std;
//Named constants – residential customers
const double RES_BILL_PROC_FEES = 4.50;
const double RES_BASIC_SERV_COST = 20.50;
const double RES_COST_PREM_CHANNEL = 7.50;
//Named constants – business customers
const double BUS_BILL_PROC_FEES = 15.00;
const double BUS_BASIC_SERV_COST = 75.00;
const double BUS_BASIC_CONN_COST = 5.00;
const double BUS_COST_PREM_CHANNEL = 50.00;
float tax;
// Function Prototypes
float residential()
{
int numOfPremChannels;
float amountDue;
cout << "Enter the number"
<< " of premium channels: ";
cin >> numOfPremChannels;
cout << endl;
amountDue = RES_BILL_PROC_FEES
+ RES_BASIC_SERV_COST
+ numOfPremChannels *
RES_COST_PREM_CHANNEL;
return amountDue;
}
float business()
{
int numOfBasicServConn;
int numOfPremChannels;
float amountDue;
cout << "Enter the number of basic "
<< "service connections: ";
cin >> numOfBasicServConn;
cout << endl;
cout << "Enter the number"
<< " of premium channels: ";
cin >> numOfPremChannels;
cout << endl;
if (numOfBasicServConn<= 10)
amountDue = BUS_BILL_PROC_FEES
+ BUS_BASIC_SERV_COST
+ numOfPremChannels *
BUS_COST_PREM_CHANNEL;
else
amountDue = BUS_BILL_PROC_FEES
+ BUS_BASIC_SERV_COST
+ (numOfBasicServConn - 10) *
BUS_BASIC_CONN_COST
+ numOfPremChannels *
BUS_COST_PREM_CHANNEL;
return amountDue;
}
void change1(double change, int& quarters, int& dimes, int& nickels, int& pennies)
{
const int QUARTER = 25;
const int DIME = 10;
const int NICKEL = 5;
quarters = change / QUARTER;
change = change % QUARTER;
dimes = change / DIME;
change = change % DIME;
nickels = change / NICKEL;
pennies = change % NICKEL;
return;
}
int main()
{
//Variable declaration
int accountNumber;
char customerType;
int numOfPremChannels;
int numOfBasicServConn;
double amountDue;
double change;
int Dollars;
double cash;
int quarters, dimes, nickels, pennies;
cout << fixed << showpoint;
cout << setprecision(2);
cout << "This program computes a cable "
<< "bill." << endl;
cout << "Enter account number (an integer): ";
cin >> accountNumber;
cout << endl;
cout << "Enter customer type: "
<< "R or r (Residential), "
<< "B or b (Business): ";
cin >> customerType;
cout << endl;
switch (customerType)
{
case 'r':
case 'R':
amountDue = residential();
break;
case 'b':
case 'B':
amountDue = business();
break;
default:
cout << "Invalid customer type." << endl;
}//end switch
amountDue = amountDue + (amountDue * .07);
cout << "Account Number: " << accountNumber << endl;
cout << "Amount Due: $" << amountDue << endl;
cout << "How much cash will you be paying with?" << endl;
cin >> cash;
change = cash - amountDue;
Dollars = change;
change = change - Dollars;
cout << "Dollars: " << Dollars << endl;
cout << "Cents: " << change << endl;
change1(change,quarters,dimes,nickels,pennies);
cout << "Quarters: " << quarters << endl;
cout << "Dimes: " << dimes << endl;
cout << "Nickels: " << nickels << endl;
cout << "Pennies: " << pennies << endl;
return 0;
}
|