Step 1: The program should have a FUNCTION that displays a screen that shows whi
ID: 3625880 • Letter: S
Question
Step 1: The program should have a FUNCTION that displays a screen that shows which seats are available and which are taken. Seats that are taken should be represented by a # symbol and seats that are available should be represented by a * symbol. The first thing your program should do is initialize all of the seats to available (*) and display the seating chart. (HINT: The seating chart should be a two dimensional array.) Here is an example of the seating chart with all seats initialized to available.Seats: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Row 0 * * * * * * * * * * * * * * * * * * * *
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 * * * * * * * * * * * * * * * * * * * *
Step 2: Each row in the auditorium has a different ticket price. So tickets in row 0 may be 5.00 each and tickets in row 1 may be 10.00 each. Your program should have a FUNCTION that reads the ticket price of each row from an input file called prices.dat. The ticket price for each row should be stored in a one dimensional array.
Step 3: Your program should have variables tracking the total number of tickets sold and the total revenue for all tickets sold.
Step 4:
Your program should allow the user to sell tickets one at a time. The user should be able to sell as many tickets as they would like (you need a loop for this). Do this with some sort of prompt or menu asking the user if they would like to sell another ticket. Don’t forget to validate input data if you need to.
To allow the user to sell a ticket your program should have the user enter a row number and a seat number for the ticket they would like to sell. The program should do four things with this information:
1. It should check to see if the seat is available. If the seat is taken the program should not allow the user to sell the ticket. If this happens, print a message to the user saying the ticket is not available and prompt the user to see if they would like to sell another ticket.
2. If the seat is available the program should update the seating chart by putting a taken symbol (#) in that seat’s position in the chart.
3. The program should then look up the row price for the seat sold. Your program should have a variable tracking the total revenue, the price of the seat sold should be added to this total after each sale.
4. Your program should have a variable tracking the total tickets sold. The next thing your program should do when selling a ticket is update the total tickets sold.
Step 5: Once the user is finished selling tickets print out an updated seating chart followed by the total tickets sold and the total revenue generate from those tickets.
NOTE: You are required to use two arrays in this program, one for the seating chart and one to store the prices for each row. You are also required to use two functions: one to display the seating chart and one to read in the price per row data and store it in the array with the prices for each row in it. You may use other functions if you want to but they are not required.
Some DATA to Test Your Program With
NOTE: This is DATA to TEST your program with; it’s not part of the program.
Row #
Ticket Price
0
40.00
1
40.00
2
35.00
3
35.00
4
35.00
5
30.00
6
30.00
7
25.00
8
25.00
9
25.00
10
12.50
11
12.50
12
12.50
13
9.50
14
9.50
Sell the Following Tickets (row, seat): (0,8), (0,9), (0,10), (0,18), (0,19), (2, 5), (2,6), (5,0) ,(5,1), (5,2), (7,7),(7,8), (9,1),(9,9),(9,10),(11,11),(12,13),(12,14),(12,15), (14,4),(14,5) (14,6),(14,7)
Output with this test data:
UPDATED SEATING CHART AND SALES INFO:
Seats: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Row 0 * * * * * * * * # # # * * * * * * * # #
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 * * * * # # # # * * * * * * * * * * * *
TOTAL TICKETS SOLD: 23
TOTAL REVENUE: $ 573.00
Explanation / Answer
please rate - thanks
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#define rows 15
#define seats 20
void display(char [][seats]);
void getPrices(double[]);
int getSeat(char[][seats]);
int main()
{double prices[rows];
int i,j,choice;
int totalSold=0;
double revenue=0;
char theater[rows][seats];
for(i=0;i<rows;i++)
for(j=0;j<seats;j++)
theater[i][j]='*';
getPrices(prices);
for(; ; )
{cout<<"* indicates available ";
display(theater);
cout<<"Menu: 1. sell ticket 2. get sales summary and exit ";
cin>>choice;
if(choice==1)
{j=getSeat(theater);
if(j>=0)
{totalSold++;
revenue+=prices[j];
}
}
else if(choice==2)
{cout<<"UPDATED SEATING CHART AND SALES INFO: ";
display(theater);
cout<<"TOTAL TICKETS SOLD: "<<totalSold<<endl;
cout<<"TOTAL REVENUE: $ "<<setprecision(2)<<fixed<<revenue<<endl;
system("pause");
return 0;
}
else
cout<<"Invalid choice ";
}
}
int getSeat(char t[][seats])
{int i,j;
cout<<"enter row: ";
cin>>i;
cout<<"enter seat: ";
cin>>j;
if(i>=0&&i<rows&&j>=0&&j<seats)
if(t[i][j]=='*')
{t[i][j]='#';
return i;
}
cout<<"invalid seat choice ";
return -1;
}
void display(char t[][seats])
{int i,j;
cout<<"seats:";
for(i=0;i<seats;i++)
cout<<setw(3)<<i;
cout<<endl;
for(i=0;i<rows;i++)
{cout<<"Row "<<setw(2)<<i;
for(j=0;j<seats;j++)
cout<<setw(3)<<t[i][j];
cout<<endl;
}
}
void getPrices(double p[])
{ int i;
ifstream input;
input.open("prices.dat"); //open file
if(input.fail()) //is it ok?
{ cout<<"prices file did not open please check it ";
system("pause");
system("exit");
}
for (i=0;i<rows;i++)
input>>p[i];
input.close();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.