This is a question from C++ from control structures through objects, eith editio
ID: 3665568 • Letter: T
Question
This is a question from C++ from control structures through objects, eith edition.
By using 2D arrays and passing them to functions, write a program that can be used by a small theater to sell tickets for performances. The theater’s auditorium has 15 rows of seats, with 30 seats in each row. The program should display a screen that shows which seats are available and which are taken. For example, the following screen shows a chart depicting each seat in the theater. Seats that are taken are represented by an * symbol, and seats that are available are represented by a # symbol : (PICTURE WOULD NOT PASTE) Here is a list of tasks this program must perform:
1) When the program begins, it should ask the user to enter the seat prices for each row.
a. The prices can be stored in a separate array
b. Alternatively, the prices may be read from a file
2) Once prices are entered, the program should display a seating chart similar to the one shown above.
3) The user may enter the row and seat numbers for tickets being sold.
4) Every time a ticket or group of tickets is purchased, the program should display the total ticket prices and update the seating chart.
a. The program should keep a total of all ticket sales. The user should be given an option of viewing this amount.
5) The program should also give the user an option to see a list of:
a. How many seats have been soldb. How many seats are available in each row, and
c. How many seats are available in the entire auditorium.
6) Input Validation: When tickets are being sold, do not accept row or seat numbers that do not exist. When someone requests a particular seat, the program should make sure that seat is available before it is sold.
Explanation / Answer
Executable Code
Code
#include <iostream>
#include <iomanip>
using namespace std;
/* Declaring functions & varaibles */
int menu ();
void chart ();
const char reserved = '*';
const char notreserved = '#';
const int row = 15;
const int column = 30;
char map [row][column];
double ticketPrice;
int totalCost = 0;
int seat1 = 0;
int seat2 = 450;
int stop = 1;
/* main program */
int main ()
{
const int NoOfRows = 15;
int ticketPrice [NoOfRows];
int row1, column1, ticketPrice1;
int userOption;
cout << " * Welcome to Theater *" << endl;
cout << endl ;
for (int counter = 1; counter < row+1; counter++)
{
cout << "Enter the ticketPrice for each row " << (counter + 1) << ": ";
cin >> ticketPrice [counter];
}
for (int a = 0; a < row; a++)
{
for (int b = 0; b < column; b++)
map [a][b] = notreserved;
}
int selection;
do
{
selection = menu();
/* case selection */
switch (selection)
{
/* cases */
case 1:
cout << "Show Seat Price"<<endl<<endl;
for (int counter = 0; counter < row; counter++)
{
cout << "TicketPrice for row " << (counter + 1) << ": ";
cout << ticketPrice [counter] << endl;
}
break;
case 2:
cout << "Buy a Ticket"<<endl<<endl;
do
{
cout << "Select row u like 2 sit: ";
cin >> row1;
cout << "Select seat u like 2 sit: ";
cin >> column1;
if (map [row1] [column1] == '*')
{
cout << "Sorry! seat is reserved, Please select another seat!!!";
cout << endl;
}
else
{
ticketPrice1 = ticketPrice [row1] + 0;
totalCost = totalCost + ticketPrice1;
cout << "ticket costs: " << ticketPrice1 << endl;
cout << "Confirm ur booking??? Enter (1-YES or 2-NO)";
cin >> userOption;
seat2 = seat2 - userOption;
seat1 += userOption;
if (userOption == 1)
{
cout << "Ur ticket confirmed" << endl;
map [row1][column1] = reserved;
}
else if (userOption == 2)
{
cout << "Like to book another seat??? (1-YES or 2-NO)";
cout << endl;
cin >> stop;
}
cout << "Like to book another seat???(1-YES or 2-NO)";
cin >> stop;
}
}
while (stop == 1);
break;
case 3:
cout << "Show Seats Available"<<endl<<endl;
chart ();
break;
case 4:
cout << "Show Seat Sales"<<endl<<endl;
break;
case 5:
cout << "end" <<endl;
break;
default : cout << "Error input"<<endl;
}
}
while (selection != 5);
return 0;
}
/* Menu Method */
int menu()
{
int MenuSelect;
cout << endl << endl;
cout << " MAIN MENU"<<endl;
cout << " 1. View Seat Price"<<endl;
cout << " 2. Buy a Ticket"<<endl;
cout << " 3. Show Available Seats"<<endl;
cout << " 4. Show Ticket Sales"<<endl;
cout << " 5. End program"<<endl;
cout << "_____________________"<<endl<<endl;
cout << "Enter ur selection:";
cin >> MenuSelect;
cout << endl << endl;
return MenuSelect;
}
/* Show Chart Method */
void chart ()
{
cout << " All Seats" << endl;
cout << " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30"<<endl;
for (int counter = 0; counter < 15; counter++)
{
cout << endl << "Row " << (counter + 1);
for (int counter2 = 0; counter2 < 30; counter2++)
{
cout << " " << map [counter] [counter2];
}
}
cout << endl;
}
Output
* Welcome to Theater *
Enter the ticketPrice for each row 1: 1
Enter the ticketPrice for each row 2: 1
Enter the ticketPrice for each row 3: 1
Enter the ticketPrice for each row 4: 2
Enter the ticketPrice for each row 5: 2
Enter the ticketPrice for each row 6: 2
Enter the ticketPrice for each row 7: 3
Enter the ticketPrice for each row 8: 3
Enter the ticketPrice for each row 9: 3
Enter the ticketPrice for each row 10: 4
Enter the ticketPrice for each row 11: 4
Enter the ticketPrice for each row 12: 4
Enter the ticketPrice for each row 13: 5
Enter the ticketPrice for each row 14: 5
Enter the ticketPrice for each row 15: 5
MAIN MENU
1. View Seat Price
2. Buy a Ticket
3. Show Available Seats
4. Show Ticket Sales
5. End program
_____________________
Please enter your selection:2
Buy a Ticket
Select row u like 2 sit: 0
Select seat u like 2 sit: 0
ticket costs: 1
Confirm ur booking??? Enter (1 for YES or 2 for NO)1
Ur ticket booking confirmed
Like to book another seat???(1 for YES or 2 for NO)2
MAIN MENU
1. View Seat Price
2. Buy a Ticket
3. Show Available Seats
4. Show Ticket Sales
5. End program
_____________________
Please enter your selection:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.