Starting from:

$25

BGU-Assignment 1 Solved

3 Assignment Definition
In our studio, we offer many workout plans (options). We have talented trainers who are experts in all of our workout options (Yoga, Pilates, CrossFit, etc.), where each exercise can be Cardio Anaerobic or Mixed. For example, Yoga is considered an anaerobic exercise, while spinning (cycling) is a mixed exercise.


The program will get a config file as an input, including all required information about the fitness studio opening - the number of trainers, how many customers each trainer can handle, and details about the studio's possible workouts. A detailed description of the input file will be defined in section 3.5.

Each trainer is capable of performing all of the suggested workout types. There are four types of customers in this studio. Each customer type has a unique workout strategy. A customer may request a workout from a trainer more than once. In such cases, some customers may order an additional and (maybe) different activity. In part 3.3, there is a detailed description of those strategies.

Each trainer in the studio has a limited amount of available spots in their workout session (provided in the config file). Each trainer can handle multiple customers with more than one type of workout simultaneously. In this studio, it's impossible to add new customers to an open workout session (open trainer), but it's possible to move customers from one workout session to another between different trainers under the trainer’s capacities.

The trainer's salary is the total price of all workout that was ordered for that trainer.

3.1 The Program flow

The program receives the path of the config file as the first command-line argument

string configurationFile = argv[1]

The config file contains the info about the number of trainers, the trainer’s capacities, and the workout that is available in the studio (workout options). Further described in section 3.5.

Once the program starts, it opens the studio by calling the start() function, followed by printing "Studio is now open!" to the screen.

Then the program waits for the user to enter an action to execute. After each executed action, the program waits for the next action in a loop. The program ends when the user enters the action "closeall" (See actions in part 3.4).

3.2 Classes

Studio – This class holds a list (Vector) of trainers and workout plans that the studio offers.

Trainer – This class represents a trainer in the studio. Each trainer has a finite number of available spots (int capacity, provided in the config file). It also holds a status flag bool open that indicates whether the trainer’s workout session is in progress, a list of workout plans done for this trainer’s workout session, and a list of customers. Trainer id’s start from 0.

Workout – This class represents a workout from the workout plan. It has an id, name, price, and type. The ID of a workout is the order in which he appeared in the config file (will be further described).

● enum WorkoutType - An enumeration is a user-defined data type that consists of integral constants. Define an enumeration by using the keyword enum. By default, the first element is 0, and the second is 1, and so on. You can change the default value of an enum element during declaration (if necessary).

Customer – This is an abstract class for the different customer classes. There are several types of customers, and each of them has a different workout ordering strategy. Each customer who arrives at the studio will get a number (id) that will serve as an identifier as long as he participates in a workout session. This number will be a serial number of all customers that arrived so far, starting from 0 (the first customer will get 0, the second customer will get 1, etc.). Note that this “id” serves as a temporary identifier- if a customer leaves a workout session and then comes back, he will get new ID (ID will appear only once).

The class has a pure virtual method order(workout_options), which receives the workout_options and returns a vector of workouts that the customers ordered. Ordering strategies are further described in 3.3.

BaseAction – This is an abstract class for the different action classes. The motivation for keeping a BaseAction class is to enable logging multiple action types.  The class contains a pure virtual method act(Studio& studio) which receives a reference to the studio as a parameter and performs an action on it; A pure virtual method toString() which returns a string representation of the action; A flag which stores the current status of the action: "Completed" for successfully completed actions, and "Error" for actions that couldn't be completed.

After each action is completed- if the action was completed successfully, the protected method complete() should be called to change the status to "COMPLETED." If the action resulted in an error, then the protected method error(std::string errorMsg) should be called to change the status to "ERROR" and update the error message.

When an action results in an error, the program should print to the screen: "Error: <error_message>"

 More details about the actions will be provided in section 3.4.

3.3 Ordering strategies

Sweaty Customer – This customer loves to sweat and always orders all the cardio activities from the beginning of the work_options to their end (as is received in the input file). (3-letter code – swt)

Cheap Customer – This is a customer that always orders the cheapest workout from the workout options. This customer orders only once. (3-letter code – chp)

Heavy Muscle Customer – This type of customer is all about the muscles. They only perform anaerobic exercises (don't try to talk them out of it!). They always order all the anaerobic exercises from the most expensive to the cheapest. (3-letter code – mcl)

Full Body Customer– This type of customer is all about the versatility of the workout. They always start with the cheapest cardio exercise offered, continue to the most expensive mix-type workout, and finish with the cheapest anaerobic exercise they can find. (3-letter code – fbd) Notes: 

●     When the strategy is ordering the "most expensive" or "cheapest" exercise, and there is more than one such exercise, the customer will order the exercise with the smallest id.

3.4 Actions

Below is the list of all actions that the user can request. Each action should be implemented as a class derived from the class BaseAction.

●     OpenTrainer – Opens a given trainer's workout session and assigns a list of customers (Customer object). If the trainer doesn't exist or the trainer's workout session is already open,

“Error: Trainer does not exist or is not open”
this action should result in an. Each customer has

a unique id, as described earlier (Section 3.2), in addition to their name. A trainer can receive more than one customer with the same name.

                        ○    Syntax:

open <trainer_id> <customer1>,< customer1_strategy> <customer2>,<customer2_ strategy>.

○    where the <customer_strategy> is the 3-letter code for the ordering strategy as described in section 3.3.

                        ○    example:

"open 2 Shalom,swt Dan,chp Alice,mcl Bob,fbd"

Will open a workout session with trainer number 2. If trainer number 2 doesn’t have an open session and has at least four available spots. If the customer list is bigger than the trainer capacity then you should insert the customers you can (by the order of the list) and the rest of them will be ignored and won't get an id.

You can assume that customer names consist of one word (without spaces).

●     Order – When the customers enter the trainer's workout session, they can request different workout plans. This function starts the workout session by the order that was given to the trainer. After each open (OpenTrainer), you can assume that an order can occur only once. This function will perform an order from each customer in the trainer's group, and each customer will order according to his strategy. After finishing with the orders, a list of all orders should be printed. If the trainer doesn't exist or isn't open, this action should result in an error: "Trainer does not exist or is not open".

 ○ Syntax: order <trainer_id> ○ Example:

"order 2" - Start the group exercise of trainer number 2, and then print:

Shalom Is Doing Zumba

Shalom Is Doing Rope Jumps

Dan Is Doing Rope Jumps

Alice Is Doing Pilates

Alice Is Doing Yoga

Bob Is Doing Rope Jumps

Bob Is Doing CrossFit

Bob Is Doing Yoga

●     MoveCustomer – Moves a customer from one trainer to another. Also, it moves all orders made by this customer from the origin trainer's salary to the new trainer's bill salary. If the origin trainer has no customers left after this move, the program will close his session. If either the origin or destination trainer is closed or doesn't exist, or if no customer with the received id is at the origin trainer's session, or if the destination trainer has no available spots for additional customers, this action should result in an error: "Cannot move customer". This action can only occur after the workout session has started (OpenTrainer).

○ Syntax: move <origin_trainer_id> <dest_trainer_id> <customer_id> ○ Example:

"move 2 3 5" will move customer 5 from trainer 2 to trainer 3.

●      Close – Closes a given trainer session. Should print the salary of the trainer to the screen. After this action, the trainer can accept new customers and can have an open session. The trainer's salary is accumulated, meaning that after each session, the salary is accumulated for the same trainer. If the trainer doesn't exist or the session isn't open, this action should result in an error: "Trainer does not exist or is not open". ○ Syntax: close <trainer_id> ○ Example:

"close 2" closes trainer 2, and then prints:

"Trainer 2 closed. Salary 740NIS"

●     CloseAll – Closes all workout sessions in the studio, and then closes the studio and exits. The salaries of all the trainers that were closed by that action should be printed sorted by the trainer id in increasing order. Note that if all workout sessions are closed in the studio, the action will just close the studio and exit. This action never results in an error.

○    Syntax: closeall ○      Example: "closeall" will print:

"Trainer 2 closed. Salary 740NIS"
 
"Trainer 4 closed. Salary 600NIS"
"Trainer 5 closed. Salary 330NIS"
●     PrintWorkoutOptions – Prints the available workout options of the studio. This action never results in an error.

Each workout option in the studio should be printed in the following manner: <workout_name> <workout_type> <workout_price>

○    Syntax: workout_options ○    Example:

○ "workout_options" will print:

Yoga, Anaerobic, 90

 Pilates, Anaerobic, 110

Spinning, Mixed, 120

Zumba, Cardio, 100

Rope Jumps, Cardio, 70

CrossFit, Mixed, 140

●   

More products