4 3 5 19 6 16 11 30 9 29 15 26 10 29 7 18 13 25 3 12 9 2 4 11 10 24 5 23 13 10 1
ID: 3746615 • Letter: 4
Question
4 3 5 19 6 16 11 30 9 29 15 26 10 29 7 18 13 25 3 12 9 2 4 11 10 24 5 23 13 10 15 5 12 19 11 17 5 24 5 23 8 19 14 27 5 18 6 22 13 27 1 15 5 21 15 8 4 28 8 23 11 4 2 12 4 7 6 28 15 21 9 18 4 3 6 15 2 19 4 11 11 11 3 1 2 14 8 8 13 12 4 13 9 11 14 27 10 11 15 24 4 3 5 19 6 16 11 30 9 29 15 26 10 29 7 18 13 25 3 12 9 2 4 11 10 24 5 23 13 10 15 5 12 19 11 17 5 24 5 23 8 19 14 27 5 18 6 22 13 27 1 15 5 21 15 8 4 28 8 23 11 4 2 12 4 7 6 28 15 21 9 18 4 3 6 15 2 19 4 11 11 11 3 1 2 14 8 8 13 12 4 13 9 11 14 27 10 11 15 24 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 a # symbol, and seats that are available are represented by a symbol You wil read the input file "tickets.txt" to read the initial condition of the theater. In the file, each line will represent one seat by a row and column number. For instance, if the file content is as follows: 10 15 5 20 8 13 This means three tickets were sold. And the seat location of the first ticket is 10th row and 15th column. The location of the second seat is 5th row and 20h column. And the location of the third seat is 8th row and 13th column. Your program starts with showing a menu to the user. In the menu there will be 5 options as follows: 1. View Current Seats a. This menu will show the current seat conditions as shown in the above figure. 2. Sell Ticket a. Program will ask user the row and column number of the seat. And will mark that seat as sold. (Also, a warning message if the seat was already ide sold) 3. Refund Ticket a. It will ask user to enter row and column number. If the seat was sold,it will mark it unsold. (Also, provide aExplanation / Answer
/*This c++ program uses various functions to handle ticketing.
Compile this program using g++
*/
/*
NOTE:
string function is used for easy handling with file..
otherwise 2D array can be createed to handle the same*/
#include<iostream> //Necessary file to include
#include<fstream>
#include<string.h>
using namespace std;
void view_tickets(); //Functions definition
int sell_tickets(string line);
int refund_tickets(string line);
int save_tickets(string line);
int clear_entry(string deleteLine);
int main() //Main function
{
string _row,_column;
int choice;
int x,y=0;
do //Menu
{
cout<<" ==========================TICKETS BOOKING==================== ";
cout<<" ===============================MENU========================== ";
cout<<"1. VIEW CURRENT SEATS ";
cout<<"2. SELL TICKETS ";
cout<<"3. REFUND TICKET ";
cout<<"4. SAVE DATA FILE ";
cout<<"5. EXIT THE PROGRAM ";
cout<<" Please enter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
view_tickets();
break;
case 2:
cout<<" PLease enter row and column(give one space between row and column) :";
cin>>_column;
sell_tickets(_column);
break;
case 3:
cout<<" PLease enter row and column(give one space between row and column) :";
cin>>_column;
refund_tickets(_column);
break;
case 4:
cout<<"File is updated sucessfully!!!!"
break;
case 5:
break;
default:
cout<<" Oops!!! You entered an invalid choice!!! PLease Try again";
}
}while(choice!=5);
return 0;
}
void view_tickets()
{
ifstream ReadFile;
ReadFile.open("test.txt");
char output[600];
if(ReadFile.is_open())
{
while(!ReadFile.eof())
{
ReadFile>>output;
cout<<output<<" ";
}
}
ReadFile.close();
}
int sell_tickets(string line)
{
ifstream ReadFile;
ReadFile.open("test.txt");
char output[600];
if(ReadFile.is_open())
{
while(!ReadFile.eof())
{
ReadFile>>output;
if(strcmp(output,line)==0)
cout<<"This ticket number is already sold!!! Please book another one "
else
cout<<"Ticket booked sucessfully!!! ";
save_tickets( line);
}
}
ReadFile.close();
}
int refund_tickets(string line)
{
ifstream ReadFile;
ReadFile.open("test.txt");
char output[600];
if(ReadFile.is_open())
{
while(!ReadFile.eof())
{
ReadFile>>output;
if(strcmp(output,line)==0)
clear_entry(line);
else
cout<<"Wrong entry !!! Please try again";
}
}
ReadFile.close();
}
int save_tickets(string line)
{
ofstream outfile;
outfile.open("test.txt",std::ios_base::app)
outfile<<line;
}
int clear_entry(string deleteLine)
{
ifstream sup;
sup.open("test.txt");
ofstream temp;
temp.open("temp.txt");
while (getline(sup,line))
{
if (line != deleteline)
{
temp << line << " ";
}
}
temp.close();
sup.close();
remove("test.txt");
rename("temp.txt","test.txt");
cout <<" ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.