Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help. This is using stacks and queues using c++. I need help if my executive class is on the write track. Elevator Action! You are

Help. This is using stacks and queues using c++. I need help if my executive class is on the write track.

Elevator Action!

You are being placed in charge of running an elevator in an office building. People enter your building on the ground floor to wait in line for the elevator.

Ground floor Rules:

  • The first person in line will be the first to get on the elevator.
  • There is no cap on how many people can be waiting for the elevator

Elevator Rules:

  • It can only hold 7 people
  • The first person to get into the elevator will be last one off

You will read in from file what is happening to the elevator. You can assume the file will be well formatted, but you may not assume that the commands will be given in a logical order or have safe values. For example, the command "DROP_OFF 10" could be in the file when no one is in the elevator. When problems like this arise, you must handle the thrown exception! Do not simply disallow such actions to occur; you need to get practice catching and handling exceptions.

Commands from file:

Command Description
WAIT
  • Someone is waiting in line for the elevator
  • It will be a single word (no whitespace)
PICK_UP
  • As many people that can fit get on the elevator
DROP_OFF <#>
  • The elevator goes up into the building
  • N number of people get out
  • Then the elevator returns to the ground floor
INSPECTION
  • The status of the following is printed to the screen
    • Is the elevator empty?
    • Who will be the next to get off the elevator?
    • Who will be the next to get on the elevator?
Elevator status: The elevator is not empty. Mark will be the next person to leave the elevator. Stacy will be the next person to get on the elevator. 

Note, there is no exit command. You'll have to read until you reach the end of file.

Here's one way of reading until you reach the end of file:

while (inFileObject >> someVar) { //you just successfully read something into someVar //so you can proceed or perhaps even continue reading into other variables } 

Example File

WAIT Bart WAIT Homer WAIT Marge WAIT Lisa WAIT Maggie WAIT Fred INSPECTION WAIT Wilma WAIT Betty WAIT Barney WAIT George WAIT Jane PICK_UP INSPECTION DROP_OFF 3 PICK_UP INSPECTION 

File overview:

  • Six people get in line for the elevator
  • Inspection occurs. The following is printed:
Elevator status: The elevator is empty. No one is in the elevator. Bart will be the next person to get on the elevator. 
  • Five more people get in line for the elevator
  • The elevator is filled
  • Inspection occurs. The following is printed:
Elevator status: The elevator is not empty. Wilma will be the next person to leave the elevator. Betty will be the next person to get on the elevator. 
  • Three are dropped off
  • The elevator filled
  • Inspection occurs. The following is printed:
Elevator status: The elevator is not empty. George will be the next person to leave the elevator. Jane will be the next person to get on the elevator. 

We will test your code with files that will cause exceptions.

Example:

WAIT Kirk WAIT Spock DROP_OFF 15 

Notable departures from reality:

  • Once people have been dropped off by the elevator, they cannot get back on the elevator (in other you don't have keep track of all people in the building)
  • We don't care what floor the elevator is going to

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago