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:
seats
123456789012345678901234567890
Row 1 ***###***###*########*****####
Row 2 ####****#####***************##
Row 3 **######*************#####**##
Row 4 **######**************##******
Row 5 ********#####********#########
Row 6 ###############*********######
Row 7 #######************###########
Row 8 ***************##****#########
Row 9 ##########*********#####******
Row 10 #****************#############
Row 11 #************#######********##
Row 12 #################*********###*
Row 13 ###************########**#####
Row 14 ##############################
Row 15 ##############################

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. The prices can be stored in a separate array. (Alternatively, the prices may be read from a file.)

2) Once the prices are entered, the program should display a seating chart similar to the one shown above. The user may enter the row and seat numbers for tickets being sold. Every time a ticket or group of tickets is purchased, the program should display the total ticket prices and update the seating chart.
3) The program should keep a total of all ticket sales. The user should be given an option of viewing this amount.

4) The program should also give the user an option to see a list of how many seats have been sold, how many seats are available in each row, and how many seats are available in the entire auditorium.
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.


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

okay so i wrote the code so far, its working except i have a few issues i have come across:

1. When select option 2 to purchase a ticket, it promps me for the row and seat number, but after that it asks "Would you like to look at another seat?(1 = YES / 2 = NO)" if i pick either option the program freaks out.

2. My second issue so far is that the seating chart is not aligned when asked to display (option 3)

Go ahead and give my code a run and check out the bugs in it first hand! I would appreciate some help in fixing these from anyone. Thanks in advance!

//A program that asks the user for input to buy theater seats.

#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;


//Main Logo

	cout << "\t*********************************************************" << endl;
	cout << "\t*													   *" << endl;
	cout << "\t*	Welcome to The our small town Theater	*" << endl;
	cout << "\t*													   *" << endl;
	cout << "\t*********************************************************" << 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\n\n";
				
				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\n\n";

				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\n\n";
				Show_Chart ();
				break;

			case 4:
				cout << "View Seat Sales\n\n";
				break;

			case 5:
				cout << "quit\n";
				break;

			default : cout << "Error input\n";
		}

	} while (choice != 5);







return 0;
}

//********************************************************************************
//********************************************************************************
//**																			**
//**							  Define Functions.							 **
//**																			**
//********************************************************************************
//********************************************************************************



// Show Menu Function...

int Show_Menu()
{
	int MenuChoice;
		cout << endl << endl;
		cout << " \tMAIN MENU\n";
		cout << " 1. View Seat Prices.\n";
		cout << " 2. Purchase a Ticket.\n";
		cout << " 3. View Available Seats.\n";
		cout << " 4. View Ticket Sales.\n";
		cout << " 5. Quit the program.\n";
		cout << "_____________________\n\n";
		cout << "Please enter your choice: ";
		cin >> MenuChoice;
		cout << endl << endl;
	return MenuChoice;
}



//Show Seating Chart Function

void Show_Chart ()
{
	cout << "\tSeats" << 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\n";

		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;
}

Recommended Answers

All 20 Replies


123456789012345678901234567890
Row 1 ***###***###*########*****####
Row 2 ####****#####***************##
Row 3 **######*************#####**##
Row 4 **######**************##******
Row 5 ********#####********#########
Row 6 ###############*********######
Row 7 #######************###########
Row 8 ***************##****#########
Row 9 ##########*********#####******
Row 10 #****************#############
Row 11 #************#######********##
Row 12 #################*********###*
Row 13 ###************########**#####
Row 14 ##############################
Row 15 ##############################

okay so i wrote the code so far, its working except i have a few issues i have come across:

1. When select option 2 to purchase a ticket, it promps me for the row and seat number, but after that it asks "Would you like to look at another seat?(1 = YES / 2 = NO)" if i pick either option the program freaks out.

Doesn't happen if the user enters in a number, but if you hit a letter, yes, the stream goes bad and it loops. Either check if the stream fails using cin.fail() and loop back if the input is improper, or take the input in as a string and make sure it contains the integer, convert your string to integer, and carry on.

2. My second issue so far is that the seating chart is not aligned when asked to display (option 3)

This is going to take some finagling. I would stack your seat numbers on top of each other if they are 2 digits, like:
1 1
1 2
for 11 and 12, etc. Since some of your row numbers are more than 1 digit, you'll have to bump the first rows over a set number of spaces. Use an if condition in your printing loop.

it happens to me even if i enter a number

I compiled the code that you put up:

MAIN MENU
 1. View Seat Prices.
 2. Purchase a Ticket.
 3. View Available Seats.
 4. View Ticket Sales.
 5. Quit the program.
_____________________

Please enter your choice: 2


Purchase a Ticket

Please select the row you would like to sit in: 2
Please select the seat you would like to sit in: 5
That ticket costs: 30
Confirm Purchase? Enter (1 = YES / 2 = NO)1
Your ticket purchase has been confirmed.
Would you like to look at another seat?(1 = YES / 2 = NO)1
Please select the row you would like to sit in:

That's just one run, but I did try it repeatedly last night. What is the exact sequence that you used to get to that point?

i checked seat availability to see the chart and then continued on to choice 2

okay option 2 is working fine for me now, the problem is when i pick view available seats the program freezes

MAIN MENU
 1. View Seat Prices.
 2. Purchase a Ticket.
 3. View Available Seats.
 4. View Ticket Sales.
 5. Quit the program.
_____________________

Please enter your choice: 3


View Available Seats

        Seats
   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

Row 1 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 2 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 3 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 4 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 5 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 6 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 7 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 8 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 9 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 10 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 11 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 13 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 14 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 15 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #


        MAIN MENU
 1. View Seat Prices.
 2. Purchase a Ticket.
 3. View Available Seats.
 4. View Ticket Sales.
 5. Quit the program.
_____________________

Please enter your choice: 2


Purchase a Ticket

Please select the row you would like to sit in: 4
Please select the seat you would like to sit in: 19
That ticket costs: 42
Confirm Purchase? Enter (1 = YES / 2 = NO)1
Your ticket purchase has been confirmed.
Would you like to look at another seat?(1 = YES / 2 = NO)1
Please select the row you would like to sit in:

I can't reproduce it unless I put in a letter instead of 1 or 2... Have you changed your code since the last time you posted it?

the seating chart doesnt come up anymore, and also after picking option 2 and purchasing a ticket and selecting view ticket sales, its doesnt register or show any ticket sales

no code hasnt been changed

okay, never mind for some reason break point got inserted where it was not needed. chart is working fine, just working on alignment but option 4 is still not working

Look at lines 131-133, there is no code there. If you are saying that is the functionality missing in your program, get these portions working first.

Put some cout statements in your program for debugging the freezing (or use a debugger). Try to isolate the line that it is freezing on (so putting in statements like "Checkpoint 3" or whatever you like after it's made so much progress). I can't reproduce the problem so I won't be much help.

i have everything fixed now except the allignment of the chart and "view seat sales" option which doesnt seem to work

i have everything fixed now except the allignment of the chart and "view seat sales" option which doesnt seem to work

I've told you how to handle the alignment in a prior post, and how is view seat sales supposed to work when there is just a stub there?

what do you mean by stack one on the other?

000000000111111111122222222223
      123456789012345678901234567890
Row  1
Row  2
Row  3
...
Row 10
Row 11

This way one seat number sits over one seat position and the rows are kept neatly in line.

okay got the seating chart aligned, working on fixing the total sales option, any hints/recommendations/ideas?

One way to do it would be to go through your seating chart and use the price for each row to get a total.

got it to work, Thanks Buddy! you r a lot of help!

can any1 plz give me full code of this cinema program plzzzzzzz

No, do your own homework buddy...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.