cineama seating program help
May 3, 2016 at 5:59pm UTC
HI guys i m new here
this week i have an assignment and i got stuck in problem so need help plz help me
i want to add an array which ask for price for each rows because each row has different price row 1 has 1000 then row 2 500 user will enter the price of rowa how should i add it
here is full 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 an * symbol, and seats
that are available are represented by a # symbol:
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#include <iostream>
#include <iomanip>
#include <string>
#include <istream>
#include <fstream>
using namespace std;
const int numberOfRow = 15;
const int numberOfCol = 30;
void print(char matrix[][30], int numberOfRow, int numberOfCol);
int main()
{
char matrix[numberOfRow][numberOfCol], seat[numberOfRow][numberOfCol];
char option;
int i, j;
int row,col;
int ticketsold = 0;
bool another =true ;
for (i = 0; i < numberOfRow; i++)
for (j = 0; j < numberOfCol; j++)
matrix[i][j] = '*' ;
while (another)
{
print( matrix, numberOfRow, numberOfCol );
cout << "\nMenu:\n" ;
cout << "1) Buy ticket\n" ;
cout << "2) Total sell and exit\n\n" ;
cout << "Enter your choice : " ;
cin >> option;
cout << endl << endl;
switch (option)
{
case '1' :
{
cout << "Enter row: " ;
cin >> row;
cout << "\nEnter seat: " ;
cin >> col;
if ( matrix[row][col] == '*' )
{
matrix[row][col] = '#' ;
ticketsold++;
}
else
{
cout << "Invalid seat choice" ;
}
//total revenue
}
case '2' :
{
another=false ;
}
default :
cout << "Invalid choice" ;
}
}
}
void print(char matrix[][30], int numberOfRow, int numberOfCol)
{
int row, col, i, j;
cout << "* Seats available\n" ;
cout << "# Reserved Seats\n" ;
cout << "Seats: 0 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" << endl;
for (i = 0; i < numberOfRow; i++)
{
cout << "Row" << setw(3) << i;
for (j=0; numberOfCol > j; j++)
cout << setw(3) << matrix[i][j];
cout << endl;
}
}
May 3, 2016 at 6:17pm UTC
line 15: What's the purpose of the seat array? You don't need it.
line 24,48,48,81,82: You have the characters for taken and available reversed. The instructions state * is taken and # is available.
i want to add an array which ask for price for each rows because each row has different price row 1 has 1000 then row 2 500 user will enter the price of rowa how should i add it
The instructions don't indicate that is a requirement. However, if you want to add that feature, I would suggest starting with a const array of prices, rather than prompting for the price of each row.
const int prices[numberOfRow] = { <15 prices> };
Once you have your program working with an array of prices, then it's easy enough to change it to prompt for the price of each row if you wish.
May 3, 2016 at 6:37pm UTC
i m modifying code here is my new code see prices added optiob 3 and 4 not work
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
//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;
}
May 3, 2016 at 6:39pm UTC
when i booked a ticket from option 2 and want to see how many seats are booked option 4 does not show me so much confusion
May 3, 2016 at 6:53pm UTC
line 13: price is an unnecessary global. Get rid of it. Causes reader confusion with line 21.
line 10, 20: Duplicate constants for the same purpose. Get rid of one.
line 8,9: Good move declaring const values for FULL and EMPTY. However at line 67, you don't use the const value.
line 75: You adjust the total before the purchase is confirmed. If the user says no, total is going to be wrong.
line 89, 94: If the user says no, you ask "Would you like to look at another seat?" twice.
and want to see how many seats are booked option 4 does not show me
Option #4 doesn't do anything.
1 2 3
case 4:
cout << "View Seat Sales\n\n" ;
break ;
I strongly suggest moving lines 59-97 to a separate function. Makes your program easier to read.
Last edited on May 3, 2016 at 6:58pm UTC
May 4, 2016 at 2:02am UTC
oh shit i have duplicate many lines thanks man
can u move the lines into a seperate function and give me code with bug free?
May 4, 2016 at 2:04am UTC
option 4 code is missing means i have to write code for it
May 4, 2016 at 2:35am UTC
i m confuse how to use full and empty in line 67 then properly
May 4, 2016 at 2:51am UTC
i m tired of this can u plz give me this in working condition :(
May 4, 2016 at 4:21am UTC
i m tired of this can u plz give me this in working condition :(
Realise that respondents might be in a different time zone to you.
can u move the lines into a seperate function and give me code with bug free?
You already have functions in your program, why can't you do it? It's your job to write code, ours to help out.
AbstractionAnon has already given you a great deal of help.
May 4, 2016 at 1:51pm UTC
i m confuse how to use full and empty in line 67 then properly
Just use the name of the character literal you defined.
if (map [row2] [column2] == FULL)
i m tired of this can u plz give me this in working condition
Sorry. I'm not going to write your assignment for you. You will learn more by doing.
Post some updated code and I will try to give you as much help as I can.
May 7, 2016 at 7:16am UTC
thnaks guys its done now
Topic archived. No new replies allowed.