Question
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 |
|
PICK_UP |
|
DROP_OFF <#> |
|
INSPECTION |
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started