Question

Homework #5 - Elevator Simulation - Doubly Linked List The program needs to use a doubly...

Homework #5 - Elevator Simulation - Doubly Linked List

The program needs to use a doubly linked list.

Homework #5 - Extra Credit

Elevator Simulation Algorithm

We are going to develop an algorithm and implement in C++ to simulate a single elevator in a 10-story building. There will be some simplifying assumptions that will make this a bit less complex than a real-world implementation. The number of floors is not important, nor is the number of people getting on or getting off the elevator. The following rules apply to movement of the elevator:

  1. By default, the elevator will always begin to operate from the 1st floor.
  2. The algorithm needs to support the 2 separate directions of up and 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 the same direction, unless there are no passengers and no people waiting for the elevator with “get on” requests.
  5. When the elevator stops moving in one direction, it checks to see if there are additional “get on” requests. The elevator does not 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 or drop-offs in the same direction. In other words, the elevator does not move in the opposite direction until you receive 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 they are fixed by me, you can populate them into an array if you like.  Each event can have a maximum of 3 pieces of information, as described by #2.
  2. ‘GET ON’ has 2 parameters: the number of the floor on which a person or persons will enter the elevator and the number of the floor on which the person(s) will get off. ‘MOVE’ has no parameters but you can assign 2 parameters with values of zeros so that the 2 events are parallel.
  3. Implement the elevator as a doubly-linked list. When the elevator is moving up, it follows from the head to determine where to go to next. When it is moving down, it follows from the tail backwards.
  4. When there are no more nodes in the same direction as the elevator is moving, it checks the array for its next requests and either moves or adds “get on” requests. It then continues to move in the same direction it was moving, if there are now requests for that direction, or it reverses direction to pick up people. If the entire list is empty, it returns to the 1st floor to wait.
  5. The doubly-linked list nodes need to contain two items of information: a primary floor number to stop at and, for an arriving passenger, a secondary floor number representing the “get off”. You cannot add the “get off” as a node until the passenger has gotten on. Otherwise, you may try to discharge a passenger who is not yet on the elevator.
  6. To summarize, when you pick up a ‘GET ON’ request, add it to the 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 ON 4,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 the same direction if there are requests, (b) in the opposite direction if there are requests or (c) down to 1 if there are no requests in the list.

The output from this program should identify each of the elevator stops and whether people get off, get on, or both. You should produce output when you encounter a MOVE instruction. In other words, there should be 4 separate outputs, each identifying a set of floors and “get on” or “get off” actions.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:-

class elevator{
private:
//The Lift box the elevator controls
liftboxControlUnit & mLiftBoxCtrlUnit;   

//constructor
elevator(int Level=1, int NoOfBanks =1 );

//Destructor
~elevator();

//Triggers the search to move to the next floor if required
void moveLiftToNext();

public:

//Adds request to the queue
void addRequest(int FloorNumber){

//Add the request to the queue. The single button outside the elevator door
mLiftBoxCtrlUnit.addRequest(FloorNumber);

}

//For Emergency. Should be accessible to everyone !
void setEmergency();
void unsetEmergency();

};

typedef enum Direction{
UP,
DOWN
}direction;

class liftboxControlUnit{
private:

//The request for various floors
set<int> mRequestQueue;

//The various banks for the whole system
vector<Bank> mBanks;

//The total number of levels. Remains the same for one building
const int mTotalLevel;

//Instruction to move the box to certain level
void processRequest(){

//Do the logic to move the box.

}

//can passed to the elevator
void addRequest(int x){
mRequestQueue.insert(x);
}

//Can be set by elevator class
void setEmergency(){
//Do the required
//Set Emergency on all Banks
}

void unsetEmergency(){
//UnsetEmegency on all banks
}

void emergencyListener(){
//Listen to all the banks if emergency has been set
}

void BankFreeListener(){
//Listen to the banks if any is free

//If so then
processRequest();
}

public:
//Constructor
liftboxControlUnit(int TotalLevels, int NoOfBanks): mTotalLevel(TotalLevels){
for(int i=0 ; i lessthan NoOfBanks; ++ i)
mBanks.push_back(Bank(0,UP));
}
friend class elevator;
};

class Bank{
private:

//The dailpad inside the bank
dailpad & mpad;

//Current Location
int mPresentLevel;

//Current direction of movement
direction mDirection;

//Currently moving
bool mEngaged;

//Manipulate the bank
void move(int NoOfMoves){
setEngaged();

//Move the elevator

unsetEngaged();
}

//getters
int getPresentLevel() const;
int getDirection() const;

//setters
void setPresentLevel(int);
void setDirection(direction);

//Manipulate the engaged flag
bool isEngaged() const;
bool setEngaged();
bool unsetEngaged();

//For emergency
void reset();

//Dailpad Listener
void dailpadListener(){

}


public:
Bank(int StartingLevel, direction Direction): mPresentLevel(StartingLevel),
mDirection(Direction),
mEngaged(false),
mpad()
{

}

//For emergency . Should be available for all.
void SetEmergency();
void UnsetEmergency();
bool isEmergency();

friend class liftboxControlUnit;
};


class dailpad{

private:
//Some DS to represent the state . probably a 2D Array.

void renderDisplay();

public:

//Constructor
dailpad();

void getCommand(int x){
//Depending on the value we can do the following

//Make necessary changes to the display
renderDisplay();
}

friend class Bank;
};

Add a comment
Know the answer?
Add Answer to:
Homework #5 - Elevator Simulation - Doubly Linked List The program needs to use a doubly...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • implement a doubly-linked list in C. Each node in the linked list should contain a string,...

    implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...

  • This is a repost of my question from before. I am having trouble writting the code...

    This is a repost of my question from before. I am having trouble writting the code for this project. Below is the project description with various methods and classes the code in C++ should implement. Project Description The goal of this project is to design and develop C++ code and algorithms to control a bank of elevators, which services many floors and transports people “efficiently ", that is, as per the given specifications. A second goal is to effectively employ...

  • C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the...

    C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the sortedList class. Call your new class doublyLinkedList. Convert the baseline code into a doubly linkedlist, and thoroughly test all existing operations (make sure to check all edge conditions), and then implement the new operations below. The class should have the following additional class methods: • A reverse method: this method will reverse the order of the doubly linked list. This method takes no parameters,...

  • Part I: Create a doubly linked circular list class named LinkedItemList that implements the following interface:...

    Part I: Create a doubly linked circular list class named LinkedItemList that implements the following interface: /** * An ordered list of items. */ public interface ItemList<E> {      /**       * Append an item to the end of the list       *       * @param item – item to be appended       */ public void append(E item);      /**       * Insert an item at a specified index position       *       * @param item – item to be...

  • C++ assignment about doubly linked list

    You are required to write the following functions using this class: class Doubly_linked_list // Use a class Doubly_linked_list to represent an object {     public:     // constructor initialize the nextPtr     Doubly_linked_list()     {         prevPtr = 0; // point to null at the beginning         nextPtr = 0; // point to null at the beginning     }     // get a number     int GetNum()     {         return number;     }     // set a number     void SetNum(int num)     {         number = num;     }     // get the prev pointer     Doubly_linked_list ...

  • Write a C++ computer program that simulates the action of an elevator that is out of...

    Write a C++ computer program that simulates the action of an elevator that is out of order. After simulating the motion of the elevator, your program will display a bar chart that shows the number of times the elevator stays on each floor of a twenty-five-story building. When you arrive on the scene to begin studying the elevator, it is on the twelfth floor of the twenty-five-story building. Every five minutes the elevator either moves up one floor or down...

  • Solve it for java Question Remember: You will need to read this assignment many times to...

    Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...

  • Doubly Linked List Is there a way to further modify/simplify/improve this program? I was thinking of maybe changing how...

    Doubly Linked List Is there a way to further modify/simplify/improve this program? I was thinking of maybe changing how to get size. I'm not sure. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null; prev = null; data = 0; } /* Constructor */ public Node(int d, Node n, Node p) { data = d; next = n; prev = p; } /* Function...

  • Using C++, create a doubly linked list data structure that stores strings. At a minimum, you...

    Using C++, create a doubly linked list data structure that stores strings. At a minimum, you must have a List class that contains the list functionality (including an insert function) and a linkable object ("link node") class. For convenience, you may include the data directly or the data may be external to the link node, connected with a reference. You may use an inner class for the LinkNode and/or include the LinkNode class with the List class file if you...

  • In java Write a method public void printReverse() that prints the elements of a doubly linked...

    In java Write a method public void printReverse() that prints the elements of a doubly linked list in reverse. Write a method public void delete5FromTheEnd() which deletes the 5th element from end of the list. Note that if you reach the end then you have to reverse the direction of counting. In the main() method of the test class, create a randomly generated Doubly-Linked list of 10 Integers. Next, call the delete5FromTheEnd() method and print the lists iteratively until the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT