# include <iostream>
# include <iomanip>
# include <fstream>
usingnamespace std;
void seats(double[], int);
void mapSeats();
int main()
{
constint rowNum = 15;
double rowValue[rowNum]; //array to hold row pices
char selection;
int row2, col2;
constchar TAKEN = '#';//seats taken
constchar EMPTY = '*';//seats free
constint row = 15;//number of rows
constint col = 20;//number of col
char map[row][col];//array to hold seat chart
ifstream file;
for (int i = 0; i<row; i++)//initiating array
{
for (int j = 0; j<col; j++)
{
map[i][j] = EMPTY;
}
}
cout << "* Seats are available" << endl;
cout << "# Reserved seats" << endl;
mapSeats();
seats(rowValue, rowNum);//ask user to enter price of each row
cout << endl;
do
{
cout << "MOVIE THEATER MENU" << endl;
cout << "------------------" << endl;
cout << "1) Sell a ticket" << endl;
cout << "2) Total sell and exit" << endl;
cout << "Enter your choice: ";
cin >> selection;
if (selection == '1')
{
cout << "Enter row:";
cin >> row2;
cout << endl;
cout << "Enter seat:";
cin >> col2;
cout << endl;
// Check if seat is free
if (map[row2][col2] == TAKEN)
{
cout << "Invalid seat choice. \n";
continue; // start the loop again
}
else // and if it is - sell the ticket
map[row2][col2] = TAKEN;
// Add the next loop to immediately see the effects:
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cout << map[i][j];
}
cout << endl;
}
}
elseif (selection == '2')
{
cout << "UPDATED SEATING CHART AND SALES INFO" << endl;
mapSeats();
cout << "TOTAL TICKETS SOLD: " << endl;
cout << "TOTAL REVENUE: "<< endl;
}
else
{
cout << "Invalid choice." << endl;
}
} while (selection != '1' || selection != 'q' || selection != 'Q');
system("PAUSE");
return 0;
}
void seats(double rowPrice[], int row)
{
fstream file;
constint size = 4;
char data[size];
file.open("prices.txt", ios::in | ios::binary);
file.read(data, sizeof(data));
for (int i = 0; i < row; i++)
{
cout << data[i] << " " << endl;;
}
}
void mapSeats()
{
constchar TAKEN = '#';//seats taken
constchar EMPTY = '*';//seats free
constint rw = 15;
constint cl = 20;
cout << "Seats ";
for (int k = 0; k <20; k++) //loop to display nums 0 to 14
{
cout << fixed << "" << setw(2) << k << " ";
}
for (int i = 0; i<rw; i++)//making array display what's in it
{
cout << endl << "Row " << setw(2) << i;
for (int j = 0; j<cl; j++)
{
cout << fixed << " " << EMPTY << " ";
}
}
cout << endl;
}
this is a movie theater seating program that sells seats to user. It's almost done. I just need to fix the part where i need to read a list of integers in a txt file (prices.txt) and save them into an array to save the prices for each row.
after that, I need to be able to save all the seats sold and the total revenue made. can somebody pls show me how to code properly for these two issues?