Hello all, I'm pretty new to programming and I'm not very good at it. But I have this assignment and I can't figure out whats wrong with my program. Here is the assignment and my code is below it.
An Internet service provider has three different subscription packages for its customers:
Package A: For $15 per month with 50 hours of access provided.
Additional hours are $2.00 per hour over 50 hours.
Assume usage is recorded in one-hour increments,
Package B: For $20 per month with 100 hours of access provided.
Additional hours are $1.50 per hour over 100 hours.
Package C: For $25 per month with 150 hours access is provided.
Additional hours are $1.00 per hour over 150 hours
Write a program that calculates a customer’s monthly charges.
Implement with the following functions in a separate functions.cpp file:
getPackage
validPackage
getHours
validHours
calculatePkg_A
calculatePkg_B
calculatePkg_C
calculateCharges
showBill
Validate all input.
Demonstrate valid and invalid cases.
Show console dialog. It must be readable.
Here is what I have so far.
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
|
#include <iostream>
#include <iomanip>
using namespace std;
char getValidPkg();
char getValidHrs();
char calculatePkg_A();
char calculatePkg_B();
char calculatePkg_C();
void showBill(double chg);
double calculatePkg_A(int hrs);
double calculatePkg_B(int hrs);
double calculatePkg_C(int hrs);
double calculateCharges(char pkg, int hrs);
bool isValidPkg(char p) //checkpkg
{
return (p >= 'A' && p <= 'C') || (p >= 'a' && p <= 'c');
}
char getValidPkg() //getpkg
{
char p = 0;
do
{
cout << "Enter pkg: ";
cin >> p;
} while (!isValidPkg(p));
return p;
}
bool isValidHrs(int h) //checkhrs
{
return (h >= 0 && h <= 720);
}
char getValidHrs() //gethrs
{
int h;
do
{
cout << "Enter hours: ";
cin >> h;
} while (!isValidHrs(h));
return h;
}
double calculatePkg_A(int hrs)
{
int baseCost = 15;
int baseHrs = 50;
double extraCost = 2.0;
double cost = hrs > baseHrs ? baseCost + (hrs -
baseCost) * extraCost : baseCost;
return cost;
}
double calculatePkg_B(int hrs)
{
int baseCost = 20;
int baseHrs = 100;
double extraCost = 1.50;
double cost = hrs > baseHrs ? baseCost + (hrs -
baseCost) * extraCost : baseCost;
return cost;
}
double calculatePkg_C(int hrs)
{
int baseCost = 25;
int baseHrs = 150;
double extraCost = 1.00;
double cost = hrs > baseHrs ? baseCost + (hrs -
baseCost) * extraCost : baseCost;
return cost;
}
double calculateCharges(char p, int hrs)
{
double chg;
switch (p)
{
case 'A':
case 'a': chg = calculatePkg_A(hrs);
break;
case 'B':
case 'b': chg = calculatePkg_B(hrs);
break;
default: chg = calculatePkg_C(hrs);
}
return chg;
}
void showBill(double chg)
{
cout << "You owe: "
<< chg << endl;
}
|