A swim school has two swimming instructors. Jeff and Anna. Their current schedul
ID: 3688420 • Letter: A
Question
A swim school has two swimming instructors. Jeff and Anna. Their current schedules arc shown below. An "X" denotes a 1-hour time slot that is occupied with a lesson Write a program with array(s) capable of storing the schedules. Create a main menu that allows the user to mark a time slot as busy or free for either instructor. Also, add an option to output the schedules to the screen. Next, add an option to output all lime slots available for individual lessons (slots when at least one instructor is free). Finally, add an option to output all lime slots available for group lessons (when both instructors arc free). You, program must use two 2-D arrays for the schedules. In additions, you must use at least three functions to: Prints a schedule to the screen. Prompts the user to select an instructor. Prompts the user to schedule or free one of the instructor's slots. Sample interaction: Enter one of the following commands: p - Print schedules s - Schedule a slot f - Free a slot i - Show slots available for individual lessons g - Show available for group lessons q - Quit Command: PExplanation / Answer
#include <iostream>
using namespace std;
void printMenu(){
cout << "Enter one of the following commands:" << end1;
cout << "p - Print schedules" << end1;
cout << "s - Schedule a slot" << end1;
cout << "f - Free a slot" << end1;
cout << "i - Show slots available for individual lessons" << end1;
cout << "g - Show slots available for group lessons" << end1;
cout << "q - Quit" << end1;
}
void print(int jeff[][4], int anna[][4]){
cout << "Jeff: " << end1;
cout << " Mon Tue Wed Thu" << end1;
for(int i = 0; i < 4; ++i){
if(i == 0){
cout << "11 - 12 ";
}
else if(i == 1){
cout << "12 - 1 ";
}
else if(i == 2){
cout << "1 - 2 ";
}
else if(i == 3){
cout << "2 - 3 ";
}
for(int j = 0; j < 4; ++j){
if(jeff[i][j] == 1){
cout << "X ";
}
else{
cout << "_ ";
}
}
cout << end1;
}
cout << end1 << end1 << "Anna:" << end1;
cout << " Mon Tue Wed Thu" << end1;
for(int i = 0; i < 4; ++i){
if(i == 0){
cout << "11 - 12 ";
}
elseif(i == 1){
cout << "12 - 1 ";
}
elseif(i == 2){
cout << "1 - 2 ";
}
elseif(i == 3){
cout << "2 - 3 ";
}
for(int j = 0; j < 4; ++j){
if(anna[i][j] == 1){
cout << "X ";
}
else{
cout << "_ ";
}
}
cout << end1;
}
cout << end1;
}
void selectOrFreeSlot(int jeff[][4], int anna[][4], int set){
int ins, day, slot;
cout << "Select instructor (1 - Jeff, 2 - Anna): ";
cin >> ins;
cout << "Select Day (1 - Mon, 2 - Tue, 3 - Wed, 4 - Thu): ";
cin >> day;
cout << "Select Slot (1 - 11-12, 2 - 12-1, 3 - 1-2, 4 - 2-3): ";
cin >> slot;
if(ins == 1){
jeff[slot - 1][day - 1] = set;
}
elseif(ins == 2){
anna[slot - 1][day - 1] = set;
}
}
void lessons(int jeff[][4], int anna[][4], int ch){
int temp;
cout << " Mon Tue Wed Thu" << end1;
for(int i = 0; i < 4; ++i){
if(i == 0){
cout << "11 - 12 ";
}
elseif(i == 1){
cout << "12 - 1 ";
}
elseif(i == 2){
cout << "1 - 2 ";
}
elseif(i == 3){
cout << "2 - 3 ";
}
for(int j = 0; j < 4; ++j){
temp = jeff[i][j] + anna[i][j];
if(ch == 1 && temp < 2){
cout << "I ";
}
elseif(ch == 2 && temp == 0){
cout << "G ";
}
else{
cout << "_ ";
}
}
cout << end1;
}
}
int main(){
char option;
int jeff[4][4] = {{1, 1, 0, 0}, {0, 1, 1, 1}, {0, 1, 1, 0}, {1, 1, 1, 0}};
int anna[4][4] = {{1, 1, 0, 1}, {0, 1, 0, 1}, {1, 1, 0, 0}, {1, 0, 1, 1}};
while(true){
printMenu();
cout << "Command: ";
cin >> option;
switch(option){
case 'p':
print(jeff, anna);
break;
case 's':
selectOrFreeSlot(jeff, anna, 1);
break;
case 'f':
selectOrFreeSlot(jeff, anna, 0);
break;
case 'i':
lessons(jeff, anna, 1);
break;
case 'g':
lessons(jeff, anna, 2);
break;
case 'q':
return 0;
break;
default:
cout << "Invalid option" << end1;
}
cout << end1;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.