You didn't remove the member functions with the same name
Code:
# include <iostream>
# include <string>
# include <cstdlib>
using namespace std;
//!! A common function, not in any class
double get_monthly_total();
class Standard_Plan {
public:
void input_hours_online();
void show_info();
//!! double get_monthly_total () ;
private:
double the_hours_online;
};
class Premium_Plan {
public:
void input_hours_online();
void show_info();
//!! double get_monthly_total () ;
private:
double the_hours_online;
};
int main()
{
cout << "This will Calculate your Monthly Bill." << endl;
// This will determine whether user is in Standard Plan or Premium Plan.
char response;
cout <<
"Are you Subscribed to the Standard or Premium Plan? Enter s or p: ";
cin >> response;
if (response == 's') {
Standard_Plan aStandardPlan;
aStandardPlan.input_hours_online();
aStandardPlan.show_info();
} else {
Premium_Plan aPremiumPlan;
aPremiumPlan.input_hours_online();
aPremiumPlan.show_info();
}
system("PAUSE");
return 0;
}
void Standard_Plan::input_hours_online()
{
cout << "Enter Number of Hours Used: ";
cin >> the_hours_online;
cout << "You are Subscribed to the Standard Plan";
}
void Premium_Plan::input_hours_online()
{
cout << "Enter Number of Hours Used: ";
cin >> the_hours_online;
}
void Standard_Plan::show_info()
{
cout << get_monthly_total();
}
void Premium_Plan::show_info()
{
cout << get_monthly_total();
}
double get_monthly_total()
{
double base_charge;
double additional_charge;
double premium_discount;
char response;
int the_hours_online;
if (response == 's') {
// This will calculate charges for Standard Plan
if (the_hours_online <= 20) {
base_charge = 20.00;
cout << "Fixed Monthly Charge is: $" << base_charge << endl;
cout << "Total Monthly Bill is: $" << base_charge << endl;
}
if (the_hours_online > 20) {
base_charge = 20.00;
additional_charge = (the_hours_online - 20) * 00.50;
cout << "Fixed Monthly Charge is: $" << base_charge << endl;
cout << "Additional Charges: $" << additional_charge << endl;
cout << "Total Monthly Bill is: $" << base_charge +
additional_charge << endl;
}
}
else
{
// This will calculate charges for Premium Plan
if (the_hours_online <= 30) {
base_charge = 25.00;
additional_charge = 0.00;
premium_discount = (base_charge + additional_charge) * .10;
cout << "Fixed Monthly Charge is: $" << base_charge << endl;
cout << "10% Discount off Bill: $" << premium_discount << endl;
cout << "Total Monthly Bill is: $" << base_charge -
premium_discount << endl;
}
if (the_hours_online > 30) {
base_charge = 25.00;
additional_charge = (the_hours_online - 30) * 00.50;
premium_discount = (base_charge + additional_charge) * .10;
cout << "Fixed Monthly Charge is: $" << base_charge << endl;
cout << "Additional Charges: $" << additional_charge << endl;
cout << "10% Discount off Bill: $" << premium_discount << endl;
cout << "Total Monthly Bill is: $" << (base_charge +
additional_charge) -
premium_discount << endl;
}
}
//!! MUST return a result
return base_charge + additional_charge;
}
Study the //!! comments