Answer:
// Program is written in C++
// Comments are used for explanatory purpose
// See attachment below for output
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
void setPrices(double&, double&);
double calcCost(double, int, double, int, bool, bool, bool);
void getInfo(bool&, bool&, bool&, int&, int&);
void information();
int main()
{
//Variable Declarations
int duration, PSessions;//Duration and Personal Training Session
double regular, PSessionCost, memberCost;
//Regular Charge, Cost of One Personal Training Session and Membership Cost
bool SCitizen, Sessions, payment;
cout << fixed << showpoint << setprecision(2);
information();
cout << endl;
setPrices(regular, PSessionCost);
getInfo(SCitizen, Sessions, payment, duration, PSessions);
// cal getInfo
memberCost = calcCost(regular, duration, PSessionCost, PSessions, SCitizen, Sessions, payment);
cout << "$" << memberCost;
system("pause");
return 0;
}
void information()
{
cout << "Welcome to Stay Healty and Fit center." << endl<< "This program determines the cost of a new membership." << endl;
cout << "There's a discount of 30% for senior citizen" << endl;
cout << "Procurement for twelve months memebership attracts a discount of 15%." << endl;
cout << "Procurement of 6 or more personal training session attracts a discount 20% on each session" << endl;
}
void setPrices(double& RegularPrice, double& TrainingCost)
{
cout << "Cost of regular Membership per month: " << endl;
cin >> RegularPrice;
cout << "Cost of one personal traning session: " << endl;
cin >> TrainingCost;
}
void getInfo(bool& senCitizen, bool& bSixOrMoreSess, bool& paidTwMnth, int& nOfMonths, int& nOfPersonalTrSess)
{
//Senior Verification
char selectCl;
cout << "Are you a Senior Citizen? Please enter 'Y' or 'N': ";
cin >> selectCl;
if (selectCl == 'y' || selectCl == 'Y')
{
senCitizen = true;
}
else
senCitizen = false;
cout << endl;
//Number of personal training session.
cout << "Enter the number of personal training sessions bought: ";
cin >> nOfPersonalTrSess;
if (nOfPersonalTrSess > 5)
{
bSixOrMoreSess = true;
}
else
bSixOrMoreSess = false;
cout << endl;
//Number of months
cout << "Enter the number of months you are paying for: ";
cin >> nOfMonths;
if (nOfMonths >= 12)
{
paidTwMnth = true;
}
else
paidTwMnth = false;
}
double calcCost(double regMemPricePerMth, int nOfMonths,
double TrainingCost, int nOfPersonalTrSess,
bool senCitizen, bool bSixOrMoreSess, bool paidTwMnth)
{
double TotalCost, finalSessionCost;
//Session Discount
if (bSixOrMoreSess)
{
TrainingCost = (TrainingCost * 0.8);
}
else
{
TrainingCost = TrainingCost;
}
//Month Discount
if (paidTwMnth)
{
regMemPricePerMth = regMemPricePerMth * 0.85;
}
else
{
regMemPricePerMth = regMemPricePerMth;
}
TotalCost = regMemPricePerMth * nOfMonths;
finalSessionCost = TrainingCost * nOfPersonalTrSess;
// Check if Senior Citizen Discount Applies
if (senCitizen) {
return (TotalCost * 0.7) + finalSessionCost;
}
else {
return TotalCost + finalSessionCost;
}
}