Question: Modify sample 6-10 so that it uses a class and an object. You will need to create a classification called SPAMembership. The classification will contain

Modify sample 6-10 so that it uses a class and an object. You will need to create a classification called SPAMembership. The classification will contain private memberRate, months, and fee attributes. The class will also contain public functions to set data into the hidden attributes sent from main( ). These will be SET functions: setMemberRate and setMonths. Also have a function in your classification that calculates the charge by multiplying the memberRate * the number of months if they wish to be a member of the spa. The name of that public function can be calculateFee. It will use the hidden attributes months and memberRate to calculate the fee and the function member will return that value to the calling application.

// This is a menu-driven program that makes a function call

// for each selection the user makes.

#include

#include

using namespace std;

// Function prototypes

void showMenu();

void showFees(double, int);

int main()

{

int choice; // To hold a menu choice

int months; // To hold a number of months

// Constants for the menu choices

const int ADULT_CHOICE = 1,

CHILD_CHOICE = 2,

SENIOR_CHOICE = 3,

QUIT_CHOICE = 4;

// Constants for membership rates

const double ADULT = 40.0,

SENIOR = 30.0,

CHILD = 20.0;

// Set up numeric output formatting.

cout << fixed << showpoint << setprecision(2);

do

{

// Display the menu and get the user's choice.

showMenu();

cin >> choice;

// Validate the menu selection.

while (choice < ADULT_CHOICE || choice > QUIT_CHOICE)

{

cout << "Please enter a valid menu choice: ";

cin >> choice;

}

// If the user does not want to quit, proceed.

if (choice != QUIT_CHOICE)

{

// Get the number of months.

cout << "For how many months? ";

cin >> months;

// Display the membership fees.

switch (choice)

{

case ADULT_CHOICE:

showFees(ADULT, months);

break;

case CHILD_CHOICE:

showFees(CHILD, months);

break;

case SENIOR_CHOICE:

showFees(SENIOR, months);

}

}

} while (choice != QUIT_CHOICE);

return 0;

}

//*****************************************************************

// Definition of function showMenu which displays the menu. *

//*****************************************************************

void showMenu()

{

cout << " \t\tHealth Club Membership Menu "

<< "1. Standard Adult Membership "

<< "2. Child Membership "

<< "3. Senior Citizen Membership "

<< "4. Quit the Program "

<< "Enter your choice: ";

}

//*****************************************************************

// Definition of function showFees. The memberRate parameter *

// the monthly membership rate and the months parameter holds the *

// number of months. The function displays the total charges. *

//*****************************************************************

void showFees(double memberRate, int months)

{

cout << "The total charges are $"

<< (memberRate * months) << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!