Background: This week we’ll be creating a program that will help with selling ti
ID: 3783791 • Letter: B
Question
Background: This week we’ll be creating a program that will help with selling tickets in a theater. We will represent an empty seat with a ‘-’(hyphen) and one that has been sold with ‘#’.
Assignment: The program (driver1 and driver2) is already written. You need to create the module that contains the functions necessary to make them run. The module should be named Theater. You will need to write the following functions in it:
create(): This function takes two arguments representing the number of rows in the theater and the number of seats in each row. It initializes theater seats, storing a ‘-’(hyphen) in each seat.
print_theater(): This function takes one argument, the two dimensional list that represents the theater, and prints it to the screen. It should print contains all of the symbols stored in the two dimensional list, starting with the first row. Be sure to add the ‘ ’ characters at the end of each row. It should not show square brackets[] or commas
sell_seat(): This function allows the programmer to sell a seat. It takes two arguments: the row number and seat number. Remember that users tend to start counting at 1 (not 0). Take that into account when marking a seat as sold. Be sure to check that the seat hasn’t already been sold before marking it sold. The method returns True if the seat wasn’t already sold (and marks it sold with a #) and False if the seat had already been sold.
Explanation / Answer
#include <iostream>
#include<iomanip>
#include <string>
using namespace std;
void menuOptions();
void showChart ();
const char FULL = '*';
const char EMPTY = '#';
const int rows = 15;
const int columns = 20;
char map [rows][columns];
void availSeats();
void seatPrices();
void ticketSales();
void purchTicket();
int row2, column2, cost;
int answer;
024
double price;
int count = 0;
int total = 0;
int seat = 450;
int seat2 = 0;
int cancel = 1;
int getChoice()
{
menuOptions();
int choice;
cout << " ENTER CHOICE ---> [";
cin >> choice;
system("cls");
return choice;
}
bool doMenu()
{
switch(getChoice())
{
case 1:
availSeats();
break;
case 2:
seatPrices();
break;
case 3:
ticketSales();
break;
case 4:
purchTicket();
break;
case 5:
return false;
break;
default:
cout << " Invalid choice..." << endl;
cout << "Choose again. ";
}
return true;
}
int main()
{
system ("color 75");
while(doMenu());
system("PAUSE");
return 0;
}
void menuOptions ()
{
cout <<" C++ Theatre ";
cout <<" MENU OPTIONS ";
cout <<" *********************** ";
cout << "1. View Available Seats" << endl;
cout << "2. View Seating Prices" << endl;
cout << "3. View Ticket Sales" << endl;
cout << "4. Purchase a Ticket" << endl;
cout << "5. Exit the Program" << endl;
}
{
cout << "Legend : * = Sold "<<
<< "# = Available";
}
void seatPrices(int)
{
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;
}
cout << "View Seat Prices ";
for (int count = 0; count < rows; count++)
{
cout << "The price by row " << (count + 1) << ": ";
cout << price [count] << endl;
}
}
void ticketSales();
void purchTicket()
{
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 >> cancel;
}
cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
cin >> cancel;
}
}
while (cancel == 1);
}
void showChart ()
{
cout << " Seats" << endl;
cout << " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ";
for (int count = 0; count < 15; count++)
{
cout << endl << "Row " << (count + 1);
for (int count2 = 0; count2 < 20; count2++)
{
cout << " " << map [count] [count2];
}
}
cout << endl;
system("cls");
}//end of function showChart
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.