0

Need help writing a program for class. Here were the posted instructions:

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.)

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:

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.

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.

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.

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.

Note: The test data file for this run: prices.txt

10

10

10

9

9

9

8

8

8

7

7

7

6

6

6

I am stuck on step two where it says:

"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."

I have no idea on how to create input files or check them for that matter. Here is my code so far. I stopped in my case '1' after checking for duplicate seats. How would i then match the row with the price i want to charge from a data file?

#include <iostream>
#include <iomanip>
#include <string>
#include <istream>
#include <fstream>
using namespace std;

const int numberOfRow = 15;
const int numberOfCol = 20;

void print(char matrix[][20], 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";*/

}
}





system("pause");
}


void print(char matrix[][20], 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" <<  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;
}
}
2
Contributors
1
Reply
21
Views
4 Years
Discussion Span
Last Post by tinstaafl
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.