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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
#include <iostream>
#include <iomanip>
#include <cctype>
using namespace std;
void getPlan_Minutes(char& PLAN, int& MINUTES);
void calculateBill(char PLAN, int MINUTES,double& F,double& M,double& H,double& P,double& B);
void outputBill(char PLAN, int MINUTES,double F,double M,double H,double P,double B, int account);
//constants
double const CODE_F = 150.00; //code f - monthly charge for fixed rate plan
double const CODE_M = 5.00; //code m - monthly base charge for per minute charge plan
double const CODE_H = 40.00; //code h - monthly base charge for home customer plan
double const CODE_P = 64.00; //code p - monthly base charge for home plus customer plan
double const CODE_B = 150.00; //code b - monthly base charge for business customer plan
int main()
{
int account;
char plan;
int minutes;
char getPlan;
int getMinutes;
double billF;
double billM;
double billH;
double billP;
double billB;
// char planChosen;
//int minutesUsed;
cout << "This program will calculate and show you your cellular phone bill for one month." << endl << endl;
do {
cout << "Please input your 5 digit account number: ";
cin >> account;
cout << endl;
if ((account < 10000) || (account > 99999))
cout << "Your account number is not valid" << endl << endl;
} while ((account < 10000) || (account > 99999));
getPlan_Minutes(plan, minutes);
calculateBill(plan, minutes,billF,billM,billH,billP,billB);
outputBill(plan, minutes,billF,billM,billH,billP,billB,account);
system ("PAUSE");
return 0;
}
void getPlan_Minutes(char& PLAN, int& MINUTES)
{
cout << "AVAILABLE PLANS:" << endl;
cout << "F " << endl;
cout << "M " << endl;
cout << "H" << endl;
cout << "P" << endl;
cout << "Bs"<< endl << endl;
cout << "Please choose the letter of your plan from above: ";
cin >> PLAN;
PLAN = toupper (PLAN);
cout << endl << "Your chosen plan is: " << endl;
// Read letter of plan and output description
switch (PLAN) { //start switch plan
case 'F':
cout << "F - Fixed rate plan - $150 flat fee for unlimited minutes (no businesses)" << endl << endl;
break;
case 'M':
cout << "M - Per minute plan - $5 per month plus 21 cents per minute" << endl << endl;
cout << "Please input your minutes used: ";
cin >> MINUTES;
for( ; MINUTES < 0; )
{
cout << "Invalid number, please enter a number above 0: ";
cin >> MINUTES;
}
cout << endl;
break;
case 'H':
cout << "H - Home customer plan - $40/first 600 minutes used, plus 19 cents each additional minute"
<< endl << endl;
cout << "Please input your minutes used: ";
cin >> MINUTES;
for( ; MINUTES < 0; )
{
cout << "Invalid number, please enter a number above 0: ";
cin >> MINUTES;
}
cout << endl;
break;
case 'P':
cout << "P - Home plus customer plan - $64/first 1000 minutes, plus 17 cents each additional minute"
<< endl << endl;
cout << "Please input your minutes used: ";
cin >> MINUTES;
for( ; MINUTES < 0; )
{
cout << "Invalid number, please enter a number above 0: ";
cin >> MINUTES;
}
cout << endl;
break;
case 'B':
cout << "B - Business customer plan - $150 up to 2,000 minutes, $210 up to 3,000 minutes, $240/over 3,000 "
"minutes" << endl << endl;
cout << "Please input your minutes used: ";
cin >> MINUTES;
for( ; MINUTES < 0; )
{
cout << "Invalid number, please enter a number above 0: ";
cin >> MINUTES;
}
cout << endl;
break;
default:
cout << "Please enter a valid plan letter from above: ";
cin >> PLAN;
break;
} //end switch plan
} //end function
void calculateBill(char PLAN, int MINUTES,double& F,double& M,double& H,double& P,double& B)
{
if (PLAN == 'F')
F = CODE_F;
else if (PLAN == 'M')
M = CODE_M + (.21 * MINUTES);
else if (PLAN == 'H')
if ( MINUTES > 600)
H = CODE_H + (.19 * MINUTES);
else
H = CODE_H;
else if (PLAN == 'P')
if ( MINUTES > 1000)
P = CODE_P + (.17 * MINUTES);
else
P = CODE_P;
else if (PLAN == 'B')
if ( MINUTES <= 2000)
B = CODE_B;
else if ( MINUTES <= 3000)
B = CODE_B + 60;
else if ( MINUTES > 3000)
B = CODE_B + 90;
}
void outputBill(char PLAN, int MINUTES,double F,double M,double H,double P,double B, int account)
{
double total;
cout << "YOUR MONTHLY BILL" << endl << endl;
cout << setw(20);
cout << "Your account number: " << account << endl;
cout << "Your plan: " << PLAN << endl;
if (PLAN != 'F')
cout << "Your minutes: " << fixed << showpoint << setprecision(2) << setw(20) << MINUTES << endl;
cout << "Total due: " ;
switch (PLAN) { //start switch plan
case 'F':
total = F;
break;
case 'M':
total = M;
break;
case 'H':
total = H;
break;
case 'P':
total = P;
break;
case 'B':
total = B;
break;
}
cout<<total<<endl;
}
|