Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program to implement a priority queue using a heap, using a stack to hold values. Here is the assignment: So the user inputs a

C++ Program to implement a priority queue using a heap, using a stack to hold values.

Here is the assignment: image text in transcribed

So the user inputs a token n, and n number of gates are inserted into a stack

Events are kept in the heap. Here is what I have so far, with some pseudo code.

BinaryHeap.h file:

#ifndef BINARY_HEAP_H #define BINARY_HEAP_H #include "dsexceptions.h" #include  using namespace std; // BinaryHeap class // // CONSTRUCTION: with an optional capacity (that defaults to 100) // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // deleteMin( minItem ) --> Remove (and optionally return) smallest item // Comparable findMin( ) --> Return smallest item // bool isEmpty( ) --> Return true if empty; else false // void makeEmpty( ) --> Remove all items // ******************ERRORS******************************** // Throws UnderflowException as warranted template  class BinaryHeap { public: explicit BinaryHeap( int capacity = 100 ) : array( capacity + 1 ), currentSize( 0 ) { } explicit BinaryHeap( const vector & items ) : array( items.size( ) + 10 ), currentSize( items.size( ) ) { for( int i = 0; i  1 && x  array; // The heap array /** * Establish heap order property from an arbitrary * arrangement of items. Runs in linear time. */ void buildHeap( ) { for( int i = currentSize / 2; i > 0; i-- ) percolateDown( i ); } /** * Internal method to percolate down in the heap. * hole is the index at which the percolate begins. */ void percolateDown( int hole ) { int child; Comparable tmp = array[ hole ]; for( ; hole * 2  

Other notes:

Stack should be used to store the flights:

Struct for flights:

struct flight time type origination destination flight number gate

each struct can be hard coded.

overload "

This random number generator will be used to generate any possible delay. int myrand(int lower, int upper) //Generates random numbers from the lower to upper limit input. { return (lower + rand() % ( upper - lower +1 ) ); }

Background. Large airlines spend a great amount of effort to manage their hub airport. At DFW, for example, American Airlines serves about 50 Gates. Flights are arriving in "waves", filling up the gates. Then flights leave about 1 hour later, again one aircraft after the other. In this project you are to write program which manages some of these issues Scenario. When a flight arrives at a gate, we will consider this to be an event in time. Each aircraft's arrival will spawn another event, namely its departure exactly 60 minutes later. We will assume that randomly with probability 40% the departure is delayed by 20-40 Minutes, i e the plane leaves 80-100 minutes after its arrival. (Waiting for baggage, weather, mechanical problems...) Problem. You will have to schedule the aircraft to the gates. Time is measured in minutes starting at time 0. Flight arrivals will be at minute 2: LAX continuing to JFK 4: IAH Continuing to MSP 11: SJC continuing to BOS 17 SFO continuing to ORD 28: TUL continuing to ONT 37: BNA continuing to SEA 49: HOS continuing to DEN 3: SMF continuing to RDU 9: ABQ continuing to ATL 14 PHX continuing to MIA 19: SLC continuing to AUS 33: DCA continuing to LAS 44: MAF continuing to AMA 55: ELP continuing to MEM repeating every hour Just to make the style look a little more realistic we will have flight numbers according to the following scheme: Flights are numbered consecutively stating at number 1000 for the very first light (LAX to JFK t time 2), 1001 for the second (IAH to MSP at time 4) and 1014 for the first flight of the second hour and so forth. What you have to provide is a list that gives the fligiht number with the assigned gate number. For convenience it should also give the arrival time and departure time (in minutes from 0). If a flight could not be assigned a gate, there should be a message "Airport ful". (Obviously in the real world this is unacceptable.) The simulation should model 24 hours of operation Implementation. The events are to be kept in a priority queue implemented by a heap. The available gates are to be kept in a stack. The program should read exactly one input token, the token will be the number of gates. You may assume that the number of gates are reasonable, say between 10 and 40. The schedule of lights maybe hard-coded into the program code (so there is no need to read it from a file Submission. Submit two files electronically 1. The program. 2. A "milestone document" (PDF file) with the following: A milestone design component (for further detail see announcement page). (b) Output from a short test run (no more than two pages.) (c) Use your "simulation program" to solve the following "real-world" problem: How many gates are needed minimally to accommodate all the flights so that "Airport full" will almost never occur? Background. Large airlines spend a great amount of effort to manage their hub airport. At DFW, for example, American Airlines serves about 50 Gates. Flights are arriving in "waves", filling up the gates. Then flights leave about 1 hour later, again one aircraft after the other. In this project you are to write program which manages some of these issues Scenario. When a flight arrives at a gate, we will consider this to be an event in time. Each aircraft's arrival will spawn another event, namely its departure exactly 60 minutes later. We will assume that randomly with probability 40% the departure is delayed by 20-40 Minutes, i e the plane leaves 80-100 minutes after its arrival. (Waiting for baggage, weather, mechanical problems...) Problem. You will have to schedule the aircraft to the gates. Time is measured in minutes starting at time 0. Flight arrivals will be at minute 2: LAX continuing to JFK 4: IAH Continuing to MSP 11: SJC continuing to BOS 17 SFO continuing to ORD 28: TUL continuing to ONT 37: BNA continuing to SEA 49: HOS continuing to DEN 3: SMF continuing to RDU 9: ABQ continuing to ATL 14 PHX continuing to MIA 19: SLC continuing to AUS 33: DCA continuing to LAS 44: MAF continuing to AMA 55: ELP continuing to MEM repeating every hour Just to make the style look a little more realistic we will have flight numbers according to the following scheme: Flights are numbered consecutively stating at number 1000 for the very first light (LAX to JFK t time 2), 1001 for the second (IAH to MSP at time 4) and 1014 for the first flight of the second hour and so forth. What you have to provide is a list that gives the fligiht number with the assigned gate number. For convenience it should also give the arrival time and departure time (in minutes from 0). If a flight could not be assigned a gate, there should be a message "Airport ful". (Obviously in the real world this is unacceptable.) The simulation should model 24 hours of operation Implementation. The events are to be kept in a priority queue implemented by a heap. The available gates are to be kept in a stack. The program should read exactly one input token, the token will be the number of gates. You may assume that the number of gates are reasonable, say between 10 and 40. The schedule of lights maybe hard-coded into the program code (so there is no need to read it from a file Submission. Submit two files electronically 1. The program. 2. A "milestone document" (PDF file) with the following: A milestone design component (for further detail see announcement page). (b) Output from a short test run (no more than two pages.) (c) Use your "simulation program" to solve the following "real-world" problem: How many gates are needed minimally to accommodate all the flights so that "Airport full" will almost never occur

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions