Write a program that can be used by a small theater to sell tickets for performa
ID: 3745595 • Letter: W
Question
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 a # symbol, and seats that are available are represented by a - symbol:
You will read the input file “tickets.txt” to read the initial condition of the theater. In the file, each line will represent one seat by a row and column number. For instance, if the file content is as follows:
10 15
5 20
8 13
This means three tickets were sold. And the seat location of the first ticket is 10th row and 15th column. The location of the second seat is 5th row and 20th column. And the location of the third seat is 8th row and 13th column.
Your program starts with showing a menu to the user. In the menu there will be 5 options as follows:
View Current Seats
This menu will show the current seat conditions as shown in the above figure.
Sell Ticket
Program will ask user the row and column number of the seat. And it will mark that seat as sold. (Also, provide a warning message if the seat was already sold)
Refund Ticket
It will ask user to enter row and column number. If the seat was sold, it will mark it unsold. (Also, provide a warning message if the selected seat was not sold yet)
Save Data File
It will save the current seat conditions back into the “tickets.txt” file using the same format.
Exit Program
Exits the program
->> Please use functions for each option in the menu.
**these are the numbers from the tickets.txt input file
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
//Function Declarations
int Show_Menu (); //To show main menu
void Show_Chart (); //To show seating chart
const char FULL = '*'; //Seat taken
const char EMPTY = '#'; //Seat open
const int rows = 15; //Number of rows
const int columns = 30; //Number of seats per row
char map [rows][columns]; //Array to hold seating chart
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;
cout << " *********************************************************" << endl;
cout << " " << endl;
cout << " Welcome to The our small town Theater " << endl;
cout << " " << endl;
cout << " *********************************************************" << endl;
cout << endl << endl;
//Sets the row prices.
for (int count = 0; count < rows; count++)
{
cout << "Please enter the price for row " << (count + 1) << ": ";
cin >> price [count];
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map [i][j] = EMPTY;
}
int choice;
do
{
choice = Show_Menu(); // Shows the main menu function.
switch (choice)
{
case 1:
cout << "View Seat Prices ";
for (int count = 0; count < rows; count++)
{
cout << "The price for row " << (count + 1) << ": ";
cout << price [count] << endl;
}
break;
case 2:
cout << "Purchase a Ticket ";
do
{
cout << "Please select the row you would like to sit in: ";
cin >> row2;
cout << "Please select the seat you would like to sit in: ";
cin >> column2;
if (map [row2] [column2] == '*')
{
cout << "Sorry that seat is sold-out, Please select a new seat.";
cout << endl;
}
else
{
cost = price [row2] + 0;
total = total + cost;
cout << "That ticket costs: " << cost << endl;
cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
cin >> answer;
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
cout << "Your ticket purchase has been confirmed." << endl;
map [row2][column2] = FULL;
}
else if (answer == 2)
{
cout << "Would you like to look at another seat? (1 = YES / 2 = NO)";
cout << endl;
cin >> Quit;
}
cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
cin >> Quit;
}
}
while (Quit == 1);
break;
case 3:
cout << "View Available Seats ";
Show_Chart ();
break;
case 4:
cout << "View Seat Sales ";
break;
case 5:
cout << "quit ";
break;
default : cout << "Error input ";
}
} while (choice != 5);
return 0;
}
// Show Menu Function...
int Show_Menu()
{
int MenuChoice;
cout << endl << endl;
cout << " MAIN MENU ";
cout << " 1. View Seat Prices. ";
cout << " 2. Purchase a Ticket. ";
cout << " 3. View Available Seats. ";
cout << " 4. View Ticket Sales. ";
cout << " 5. Quit the program. ";
cout << "_____________________ ";
cout << "Please enter your choice: ";
cin >> MenuChoice;
cout << endl << endl;
return MenuChoice;
}
//Show Seating Chart Function
void Show_Chart ()
{
cout << " 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 ";
for (int count = 0; count < 15; count++)
{
cout << endl << "Row " << (count + 1);
for (int count2 = 0; count2 < 30; count2++)
{
cout << " " << map [count] [count2];
}
}
cout << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.