Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(C++)Programming Assignment. Please follow all instructions! Bold Parts are extr

ID: 3842801 • Letter: #

Question

(C++)Programming Assignment. Please follow all instructions! Bold Parts are extremely important!

It’s blockbuster movie season! Your local theater has contracted you to design a simulator for the lines of people waiting to see the various movies. The theater is trying out the following new policy:

Patrons may begin lining up 2 hours before the movie starts,

Once a patron is in line, there is no way out except through the front of the line (i.e., into the

theater). Patrons are advised to use the restroom before getting in line.

The doors to the theater are opened 1 hour before the movie starts, and patrons are let out of

the line one at a time at a rate of one per minute to give each time to find a seat without others

rushing in behind them.

Patrons may enter the line up until the start of the movie – e.g., if the movie starts at 17:30,

patrons can get in line at 17:29 but the line closes as soon as the clock reads 17:30.

If the line fills up, or the doors close with patrons left in the line, those patrons will complain to

management, leave, and write a bad review on Yelp. This is where you come in.

Your goal is to create a class to model this new policy for the theater. You will be given sample data representing the typical flow of patrons into the line and help the theater managers decide if their new policy makes sense, or if the policy will cause lines to “overflow.”

The theaterLine Class

You will create a class with the following properties:

1) A private member: an STL queue to model a single line of patrons waiting to enter a theater. The queue will hold the names of the people in line (a string).

2) A private member: the maximum number of people allowed in the queue (an int).

a. Add an accessor for this member, but not a mutator.

3) A default constructor and parameterized constructor to initialize the queue appropriately.

4) A method to return the number of patrons currently in the queue.

5) A method to add a single patron to the end of the queue if there is space available.

6) A method that both removes a single patron from the front of the queue and returns this

person’s name (a string).

Testing (below testOne is a .txt)

You will be given test files representing the flow of patrons into the line for a single movie showing. The first line of the file will list the start hour and minute, followed by size of the theater line, and the title of the movie. Each subsequent line in the file has a time (hour, followed by minute) and a list of patrons (represented by single letters for simplicity). All times are in military (24-hour) time.

Here is an example for a showing of The Empire Strikes Back which starts at 17:30, with a line size of 5. (which is testOne)

15 31 A X Y Z

15 32 B 15 33 C

15 34 D Q M P

17 29 R S T U

Your Client

Most of the code you write will be in your client. Your client should include a function to simulate the behavior of the line. It will take the start hour/min, line size, movie title, and an input file stream. In other words, your main() should open the file, read the first line, and pass all this information to the client function. Here is the header for my client function:

void simulateMovie(int startHour, int startMin, int lineSize, string title, ifstream &fs)

The client should have a loop that simulates every minute from the opening of the line to the closing of the line. Each “tick” of the clock in your loop should call appropriate functions on a theaterLine object to add and remove patrons from the line as needed. If the theater line fills up print a message to the screen to report this. When the movie begins (e.g., 17:30 in the example above), end the simulation and report how many people are still left waiting to get into the theater. Here is an example run with my program for theThe Empire Strikes Back showing above. ( which is the output of testOne)

Explanation / Answer

Here is the C++ code for the above problem,

#include <iostream>

#include <conio>

#include <ctime>

#include <cstdlib>

using namespace std;

//Structure

typedef struct{

char showname[20];

char date[12];

char time[6];

char gate[2];

} Show;

Show show = {“Romeo and Juliet”,”12-12-2012”,”12:00”,”4”};

typedef struct{

char name[30];

cha booking_ID[3];

int seats;

} Seat;

Seat choice[4][5];

void displaymenu();

void booking();

void cancel();

void seat();

void ticket();

void records();

void looping();

void exit();

//variables

int selection,i,j;

int seats_num[20]={0};

int booking_ID=100;

int seatsAvailable=20;

int main(void)

{

displaymenu();

while(selection!=5)

{

looping();

}

return 0;

void displaymenu()

{

            cout<<” ”;

            cout<<” ======== Theatre ticket reservation======= ”

                            “ MENU ”

                            “ ======= ”

                            “ 1.BOOKING ”

                            “ 2.CANCEL ”

                            “ 3.SEAT AVAILABLITY ”

                            “ 4.RECORDS ”

                            “ 5.EXIT ”;

cout<<” Enter your selection :”;

cin>>selection;

looping();

return;

}

//looping method

void looping()

{

            switch(selection)

            case 1:

            booking();

            break;

            case 2:

            cancel();

            break;

            case 3:

            seat();

            break;

            case 4:

            records();

            break;

            case 5:

            exit();

            break;

            default:

            cout<<” INVALID SELECTION!! Please try again ”;

            }

return;

}

//booking

void booking()

{

      for(i=0;i<4;i++)

      for(j=0;j<5;j++)

         {

            cout>>” Please enter seat numbers:”;

            cin>>choice[i][j].seats;

            fflush(stdin);

if(choice[i][j].seats<=seatsAvailable)

{

            cout<<” Please enter customer name:”;

            cin>>choice[i][j].name;

            fflush(stdin);

            ticket();

            booking_ID++;

     }

seatsAvailable=seatsAvailable-choice[i][j].seats;

system(“pause”);

system(“cls”);

displaymenu();

}

if(seatsAvailable<0)

{

    cout<<” ”;

    cout<<” SORRY, the show is fully booked ”;

    cout<< ======END====== ”;

    displaymenu();

}

if(choice[i][j].seats>seatsAvailable)

{

      cout<<” ”;

      cout<<” The show leave”<<seatsAvailable<<”seats ”;

      displaymenu();

      return;

}

void ticket()

{

            cout<<” ”;

            cout<<” ========THEATRE TICKET BOOKING======== ”;

            cout<<” Booking ID:”<<booking_ID<<” Show name:”<<show.showname;

cout<<” customer:”<<choice[i][j].name;

cout<<” Date:”<<show.date;

cout<<” Time:”<<show.time;

cout<<” Hall:”<<show.gate;

cout<<” Seats No.:”<<i+1,j+65;

cout<<” ============”;

return;

}

//cancel

void cancel()

{

   char cancelcustomername[80];

   cout<”Enter customer name to be cancelled:”;

   cin>>cancelcustomername;

   for(int i=0;i<4; i++)

{

   for(int j=0;j<5;j++)

       {

           if(strcmp(choice[i][j].name,cancelcustomername)==0)

            {

             //seats_num++;

choice[i][j].seats=1;

system(“pause”);

system(“cls”);

displaymenu();

return;

}

}

}

}

//seat

void seat()

{

cout<<”A B C D E ”;

for(j=0;j<5;j++)

{

          cout<<booking_ID;

}

for(i=0;i<4;i++)

{

cout<<” ”;

cout<<i+1;

}

system(“pause”);

system(“cls”);

displaymenu();

return;

}

void records() //For the staff to shoe records

{

cout<<” =================== ”;

cout<<” All show records ”;

cout<<” =================== ”;

cout<<” Seats Available left:”<<seatsAvailable;

ticket();

system(“pause”);

system(“cls”);

displaymenu();

return;

}

//EXIT

void exit()

{

cout<<” Thank you for using this system ”;

exit(1);

return;

}