Menu

[Solved] C Program Simulate Single Elevator 10 Story Building Simplifying Assumptions Make Bit Less Q37228929

C++ program to simulate a single elevator in a 10-storybuilding. There will be some simplifying assumptions that will makethis a bit less complex than a real-world implementation. Thenumber of floors is not important, nor is the number of peoplegetting on or getting off the elevator. The following rules applyto movement of the elevator:

  1. By default, the elevator will always begin to operate from the1st floor.
  2. The algorithm needs to support the 2 separate directions of upand down.
  3. The algorithm needs to support the 2 separate requirements of“get on” and “get off”.
  4. Wherever the elevator happens to be, it always continues in thesame direction, unless there are no passengers and no peoplewaiting for the elevator with “get on” requests.
  5. When the elevator stops moving in one direction, it checks tosee if there are additional “get on” requests. The elevator doesnot move again until it receives a request to move.
  6. Once the elevator starts to move, there can be no “get on”requests until the elevator has stopped and has no more pickups ordrop-offs in the same direction. In other words,the elevator does not move in the opposite direction until youreceive a request to move.

The approach to simulating the elevator is as follows:

  1. The events that you will need to simulate are described below.The 2 event types are ‘GET ON’ and ‘MOVE.   Since theyare fixed by me, you can populate them into an array if youlike.  Each event can have a maximum of 3 pieces ofinformation, as described by #2.
  2. ‘GET ON’ has 2 parameters: the number of the floor on which aperson or persons will enter the elevator and the number of thefloor on which the person(s) will get off. ‘MOVE’ has no parametersbut you can assign 2 parameters with values of zeros so that the 2events are parallel.
  3. Implement the elevator as a doubly-linked list. When theelevator is moving up, it follows from the head to determine whereto go to next. When it is moving down, it follows from the tailbackwards.
  4. When there are no more nodes in the same direction as theelevator is moving, it checks the array for its next requests andeither moves or adds “get on” requests. It then continues to movein the same direction it was moving, if there are now requests forthat direction, or it reverses direction to pick up people. If theentire list is empty, it returns to the 1st floor towait.
  5. The doubly-linked list nodes need to contain two items ofinformation: a primary floor number to stop at and, for an arrivingpassenger, a secondary floor number representing the “get off”. Youcannot add the “get off” as a node until the passenger has gottenon. Otherwise, you may try to discharge a passenger who is not yeton the elevator.
  6. To summarize, when you pick up a ‘GET ON’ request, add it tothe list, along with the ‘get off’, as an additional parameter.When the ‘GET ON’ is satisfied, you remove its node and add the‘get off’ node.

EVENT LIST

GET ON4,6                        (means a person wants to get on at 4 and get off at 6)

MOVE                                  

GET ON 8,2

GET ON 1,5

GET ON 9,3

MOVE

GET ON 10,2

GET ON 7,4

MOVE

GET ON 1,7

MOVE

NOTE: “MOVE” makes the elevator move(a) in thesame direction if there are requests, (b) in the opposite directionif there are requests or (c) down to 1 if there are no requests inthe list. The output from this program should identify each of theelevator stops and whether people get off, get on, or both. Youshould produce output when you encounter a MOVE instruction. Inother words, there should be 4 separate outputs, each identifying aset of floors and “get on” or “get off” actions.

Expert Answer


Answer to C++ program to simulate a single elevator in a 10-story building. There will be some simplifying assumptions that will m… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *