Starting from:
$35

$29

Program 4: Airport Check-in Solution

Goals



To implement and use a linked-list queue and a linked-list priority queue.



To use a controller class, a container class with two derived classes, and a polymorphic data class in one application.



To program a simple simulation.



The Idea



Jetstream Airlines wants to run their airport check-in counter as e ciently as possible without causing passengers to miss ights. They have collected data, which they claim are typical, about their groups of passengers and their arrival habits. Your job is to simulate the check-in process and nd out how many agents must be on duty to handle a ight. Your program will implement a variable number check-in agents, and you will nd out experimentally how many are needed for the given input le.




2.1 The Person Class




This is a polymorphic base class from which both check-in agents and groups of customers are derived.




It should have one data member, a name (a string).




In this class, put all the functions that are the same for the Group class and the Agent class. This includes:




A constructor with one string parameter that will initialize the name.



A default destructor that must be virtual.



Person pop(): Return the Person (Agent or Group) at the head of the list, then update the head.



bool isempty() Return true if the list is empty.



virtual void print() (This is to help you debug.) Walk through the people in the queue, starting with the head. Use each object in the queue to call the appropriate Group::print() or Agent::print() function. Note: printing a data structure should never change it. So use a local temporary scanner.



2.2 The Group Class




This data class is derived from Person. It should have two data members: the number of people in the group and the number of bags they have. De ne these functions:




A constructor with three parameters, a name and the two numbers. The constructor must pass the group name in a ctor to the constructor of the base class (Person).



A virtual default destructor.



Two get-functions for the two numbers.



virtual void print(): print the Group’s name, number of people, and number of bags.
CSCI 2226 : Program 4: Airport Check-in
2



2.3 The Agent Class




This data class is derived from Person. It needs one additional data member, a oat = the time at which the agent will nish with the current group of customers. De ne the functions below and other functions, if needed.




De ne a constructor with one parameter, a name. Pass that parameter in a ctor to the constructor of the base class, Person.



A virtual default destructor.



virtual void print(): print the Agent’s name and the time at which he will be free.



void handle(Group gp). Calculate the number of minutes it should take to check in gp, as follows:



4 minutes to process the rst person in a Group.



1 minute to handle each additional group member.



.5 minute per bag that must be checked.



Add this number of minutes to the Agent’s current time to get the next time at which the agent will be free. Store this number in the Agent object.




2.4 The PQueue Class




Derive this container class should implement a linked-list priority queue, with a head pointer, as discussed in class. Initialize to nullptr in the class de nition.




Implement these functions:




A default constructor is enough.



push(Agent ag): Add a Cell containing ag at the proper insertion slot in the queue. Update the head of the queue if that insertion was before the rst Cell.



Group pop(): Return the Agent at the head of the queue, then update the head.



bool isempty() Return true if the list is empty.



print() Print the groups in the queue, starting with the head. (This is to help you debug.) Note: printing a data structure should never change it. So use a local temporary scanner.



This class and the Queue class could both be derived from a linked list class because several of he functions are identical.. I am not recommending that because I want you to get the job done and not focus on deriving classes.




2.5 The Queue Class




This container class should implement a linked-list queue, as shown in the lecture notes, with head and tail pointers. Initialize to nullptr in the class de nition.




Implement these functions:




A default constructor is enough.



push(Group g): Add a Cell containing g to the end of the queue and update the tail.



Group pop(): Return the Group at the head of the list, then update the head.



bool isempty() Return true if the list is empyt.



print() Print the groups in the queue, starting with the head. (This is to help you debug.) Note: printing a data structure should never change it. So use a local temporary scanner.
CSCI 2226 : Program 4: Airport Check-in
3



2.6 The Simulation Class




This class is the application controller. It will have ve data members, an open input stream, a Queue for the Customers, a PQueue for the Agents, the number of Agents, and a clock (initially 0).




Implement these functions:




A constructor with one parameter, a string, which is the name of the input le. Open the le and initialize the the stream variable in the class. Accept input from the keyboard for n, the number of counter agents to use. Instantiate the empty Queue and PQueue.



Create n Agents who will all be ready at time 0.0 ; insert them onto the Pueue. The order does not matter at this time, since all these agents will start their jobs 120 minutes (2 hours) before departure time. Finally, call the getGroups() function.




getGroups(). The input le will have one family per line, and the lines will be in order of arrival time. Each line gives the family name, the number of people traveling together, and the number of bags to check:



Harrison
3
5
Kaufman
1
0
Zhang
4
9
Amin
1
2



Read each line of the le, instantiate a Group, and push it into the Queue. When this is done, you are ready to start the simulation.




CheckIn(). The check-in counter opens two hours (120 minutes) before the scheduled ight time. The goal is to get the crowd through the checkin and out to the security checkpoint by 30 minutes before departure time. Set the current time to 0. Execute the following loop until the Queue is empty:



Remove the rst Group from the Queue.



Remove the rst agent from the PQueue.



Set the simulation clock to the time stored in the Agent’s object.



Call that agent’s handle function to handle the group. The function will return a time at which the Agent will be free.



Insert the agent back into the PQueue using the free-time.



Print a line of output with the current time, the agent’s name, the passenger’s name, and the minutes he will require to check in.



When everyone in the le has been processed, print the current time and say whether the check-in was on time or not. (All passengers are supposed to reach security at least half an hour before ight time.)




Experiment with di erent numbers of agents and nd the smallest number of agents that get all the people through the process on time (in 90 minutes or less).




2.7 The main function




Write a main() function that will instantiate a Simulation using the name of a data le. Then call its CheckIn() function, which will carry out the simulation.


CSCI 2226 : Program 4: Airport Check-in
4



Submitting Your Work



I have made a short input le for use during debugging. Run your program on it until it works.



Then run it on the long le, which lists well more than 200 passengers.



Experiment with di erent numbers of agents and nd the smallest number of agents that get all the people through the process on time (in 90 minutes or less).



Hand in your code and the output from the nal run that shows how many agents you need.



Your name and \P4" should be part of the name of the zip le you submit.

More products