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
|
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
//Prototype functions
int calcRegBill(int Minutes, int& TotalMinutes);
int calcPremBill(int DayMinutes, int NightMinutes, int& TotalMinutes);
void printBill(string PlanType, string AccountNum, char& answer, double AmountDue, int TotalMinutes);
const double RegServPlan = 10.00;
const double PremServPlan = 25.00;
int main()
{
string AccountNum, PlanType;
char ServCode, answer;
int DayMinutes, NightMinutes, Minutes, TotalMinutes;
double AmountDue;
while (answer != 'n'){
cout << "Enter the account number: ";
cin >> AccountNum;
cout << endl;
cout << "Enter service code: "
<< "R or r (Regular), "
<< "P or p (Premium): ";
cin >> ServCode;
cout << endl;
switch (ServCode){
case 'r':
case 'R':
PlanType = "Regular";
cout << "Enter minutes used: ";
cin >> Minutes;
cout << endl;
AmountDue = calcRegBill(Minutes, TotalMinutes);
printBill(PlanType, AccountNum, answer, AmountDue, TotalMinutes);
break;
case 'p':
case 'P':
PlanType = "Premium";
cout << "Enter daytime (6:00am to 6:00pm) minutes used: ";
cin >> DayMinutes;
cout << "Enter nighttime (6:00pm - 6:00am) minutes used: ";
cin >> NightMinutes;
cout << endl;
AmountDue = calcPremBill(DayMinutes, NightMinutes, TotalMinutes);
printBill(PlanType, AccountNum, answer, AmountDue, TotalMinutes);
break;
default:
cout << "Invalid plan type." << endl;
}
}
cin.get();
}
int calcRegBill(int Minutes, int& TotalMinutes)
{
double RegBill;
cout << showpoint << setprecision(2)<< fixed;
TotalMinutes = Minutes;
if (TotalMinutes > 50)
RegBill = RegServPlan + ((TotalMinutes - 50) * .20);
else RegBill = RegServPlan;
return RegBill;
}
int calcPremBill(int DayMinutes,int NightMinutes, int& TotalMinutes)
{
double PremBill, AmountDueD, AmountDueN;
cout << showpoint << setprecision(2)<< fixed;
if (DayMinutes > 75)
AmountDueD = ((DayMinutes - 75) * .10);
else
AmountDueD = 0;
if (NightMinutes >= 100)
AmountDueN = ((NightMinutes - 100) * .05);
else
PremBill = 0;
PremBill = PremServPlan + AmountDueD + AmountDueN;
TotalMinutes = DayMinutes + NightMinutes;
return PremBill;
}
void printBill(string PlanType, string AccountNum, char& answer, double AmountDue, int TotalMinutes)
{
cout << showpoint << setprecision(2)<< fixed;
cout << setw(40) << left << "Cellular Account #: " << AccountNum << endl;
cout << setw(40) << left << "Type of Service: " << PlanType << endl;
cout << setw(40) << left << "Total Minutes: " << TotalMinutes << endl;
cout << setw(40) << left << "Amount Due: " << "$" << AmountDue << endl;
cout << endl;
cout << "View another bill summary? (y/n): ";
cin >> answer;
cout << endl;
}
|