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

Create a function that initially reads the seat chart from the file “chartIn.txt

ID: 3822920 • Letter: C

Question

Create a function that initially reads the seat chart from the file “chartIn.txt” and fill out a 2-dimentional array called seatChart. It then display the following menu:

------------------------ Menu ---------------------------

1. Display Seat Chart

2. Reserve Seat

3. Cancel Reservation

4. Save Seat Chart to File

5. Statistics

6. Help

7. Quit

----------------------------------------------------- ---

Please Enter Your Choice (1-7):

-------------------------------------------

The file “chartIn.txt” includes the following data:

1         A B C D

2         A B C D

3         A B C D

4         A B C D

5         A B C D

6         A B C D

7         A B C D

8         A B C D

9         A B C D

10       A B C D

PLEASE USE C++ LANGUAGE THANK YOU.

Explanation / Answer

Behaviour for 5. Statistics and 6. Help is not known so didn't included them.

#include <iostream>
#include <fstream>
#define ROW 10
#define COL 4
using namespace std;

void menu()
{
cout << "------------------------ Menu ---------------------------" << endl<<endl;
cout << "1. Display Seat Chart" << endl;
cout << "2. Reserve Seat" << endl;
cout << "3. Cancel Reservation" << endl;
cout << "4. Save Seat Chart to File" << endl;
cout << "5. Statistics" << endl;
cout << "6. Help" << endl;
cout << "7. Quit" << endl;
cout << "----------------------------------------------------- ---" << endl;
cout << "Please Enter Your Choice (1-7):" << endl;
cout << "-------------------------------------------" << endl;;
}

void display(char seating[][COL])
{
for(int i = 0; i < ROW; i++)
{
cout << (i+1) << " ";
for(int j = 0; j < COL; j++)
{
cout << seating[i][j] << " ";
}
cout << endl;
}
}

void reserveSeat(char seating[][COL])
{
while(true)
{
cout << "Enter seat number in rowNumberSeatNumber format. For example 3B: ";
char a, b;
cin >> a>> b;
int row = (a - '0');
int col = b - 'A';
  
if ((row < 1 || row > 10) || (col < 0 || col > 3))
{
cout << "Please enter a valid seat number" << endl;
}
else if(seating[row-1][col] == 'X')
{
cout << "Seat is already reserved." << endl;
}
else
{
seating[row-1][col] = 'X';
cout << "Reserved seat successfully" << endl;
return;
}
}
}

void cancelSeat(char seating[][COL])
{
while(true)
{
cout << "Enter seat number in rowNumberSeatNumber format. For example 3B: ";
char a, b;
cin >> a>> b;
int row = (a - '0');
int col = b - 'A';
  
if ((row < 1 || row > 10) || (col < 0 || col > 3))
{
cout << "Please enter a valid seat number" << endl;
}
else if(seating[row-1][col] != 'X')
{
cout << "Seat is not reserved." << endl;
}
else
{
seating[row-1][col] = 'A' + col;
cout << "Cancelled seat successfully" << endl;
return;
}
}
}

void saveToFile(char seating[][COL])
{
cout << "Enter file name: ";
char filename[100];
cin >> filename;
  
ofstream outfile(filename);
  
for(int i = 0; i < ROW; i++)
{
outfile << (i+1) << " ";
for(int j = 0; j < COL; j++)
{
outfile << seating[i][j] << " ";
}
outfile << endl;
}
  
}

int main()
{
char seating[ROW][COL];
  
ifstream myfile("chartIn.txt");
  
for(int i = 0; i < ROW; i++)
{
int a;
myfile >> a;
for(int j = 0; j < COL; j++)
{
myfile >> seating[i][j];
}
}
  

while(true)
{
menu();
int choice;
cin >> choice;
switch(choice)
{
case 1:
display(seating);
break;
case 2:
reserveSeat(seating);
break;
case 3:
cancelSeat(seating);
break;
case 4:
saveToFile(seating);
break;
case 5:
cout << "Not yet implemented" << endl;
break;
case 6:
cout << "Not yet implemented" << endl;
break;
case 7:
return 0;
default:
cout << "Wrong choice. Please choose from 1-7 only." << endl;
break;
}
}

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