Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

File I/O C++ Suppose the membership at a fitness club is $500 for individual, $8

ID: 3682186 • Letter: F

Question

File I/O

C++

Suppose the membership at a fitness club is $500 for individual, $800 for couple and $1200 for 4 people. Every month, the manager at the club says that guests will get discounts for one service per month. He provides you with the list of services that will get a discount:

Your program will be reading in a file which contains a list of services at a fitness club. The discount is determined by the type of service. For example, the file is as follows:

Cafe: Smoothies SPA: Hair and Skin

Training: 90 day challenge

Aquatics: Kids free training session

Your program should read this file and offer this discount:

If the service is Cafe, then discount is 1% of annual fitness club fee.

If the service is SPA, then discount is 10% of the annual fitness club fee.

If the service is Training, then discount is 15% of the annual fitness club fee.

If the service is Aquatics, then no discount, but program should only offer it for the family memberships.

Your program should ask the user what type of membership they have. Based on the type of membership, your program should calculate the dollar amount discount per service and list all applicable services and benefits for that user.

Your program should be reading the file in and calculating the benefits based on the type of membership. Your program should also randomly pick among the 4 discounts or 3 depending on the type of membership and display which discount the member gets for this month.

Here is the file: services.txt. Preview the documentView in a new window

service.txt:

Cafe:Smoothies

SPA:Hair and Skin

Training:90 day challenge

Aquatics:Kids free training session

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <time.h>

using namespace std;

int main(){

   string line;
   ifstream myfile ("service.txt");

  

   cout<<"Enter the type of membership you have: "<<endl;
   cout<<" 1-for Individual"<<endl;
   cout<<" 2-for Couple"<<endl;
   cout<<" 3-for 4 people"<<endl;

   int amnt,enter;
   cin>>enter;

   if(enter==1)
       amnt=500;
   else if(enter==2)
       amnt=800;
   else if(enter==3)
       amnt=1200;

   if (myfile.is_open())
   {
   while ( getline (myfile,line) )
   {
       //cout << line << ' ';

           string delimiter = ":";

           int pos = 0;
           string token;
           while ((pos = line.find(delimiter)) != string::npos) {
           token = line.substr(0, pos);
           //cout << token << endl;
           line.erase(0, pos + delimiter.length());
           }

           if(token=="Cafe")
               cout<<"Scheme(1):- Discounts: "<<(amnt*0.01)<<" Service: "<<token<<" Benefits: "<<line<<endl;
           else if(token=="SPA")
               cout<<"Scheme(2):- Discounts: "<<(amnt*0.10)<<" Service: "<<token<<" Benefits: "<<line<<endl;
           else if(token=="Training")
               cout<<"Scheme(3):- Discounts: "<<(amnt*0.15)<<" Service: "<<token<<" Benefits: "<<line<<endl;
           else if(token=="Aquatics" && amnt==1200)
               cout<<"Scheme(4):- Discounts: "<<" No discount"<<" Service: "<<token<<" Benefits: "<<line<<endl;
   }
   myfile.close();

   if(amnt!=1200){
       srand (time(NULL));
       int r = rand() % 3 + 1;
       cout<<"You are going to get Scheme Number "<<r<<" this month"<<endl;
   }
   else{
       srand (time(NULL));
       int r = rand() % 4 + 1;
       cout<<"You are going to get Scheme Number "<<r<<" this month"<<endl;
   }
   }

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote