Greetings all.
Recently I have been working on a lift simulation that consists of implementing a class called "liftObj"
here's the contents of the class liftObj:
private:
int numberOfFloors //number of floors visited by lift
int floorLift //indicates where the lift is
movement status //indicates the current status of lift
movement Floor[20] // An array holding all lift calls. If
Floor[2]=Up means a passenger at
Floor 3 is asking to go up. NA means
no lift call.
public:
enum movement{Up, Stop, Down, NA}
bool CallTo(int FloorToGo, movement m, bool inside)
// This function determines whether the Floor table is
successfully registered. The bool return type determines
this. "FloorToGo" indicates the destination floor. "m"
determines if the lift is going up or down. "inside"
determines if the call is made outside or inside the lift.
int MoveLift(void)
//This function decides the next destination and returns
the destination floor number as long as there are lift
calls pending. It also updates "status" to reflect the lift's
int getFloor(void)
//Returns the current floor number where the lift is
Other than those above I can only include additional private only functions.
Here's the alogarithm of the lift:
-Lift begins at state of Stop.
-When comparing external calls, it determines if it is at the higher
or lower portion is shorter. If the Top portion is shorter the lift
will go Up, and vice versa.
-Lift can only go Up at floor[0] and Down at floor[topfloor] where
topfloor is the top floor of the building.
-If lift is going Up, it first determines if floor number of the lower
most Up call in the Top portion,
-If not found, then it determines next the upper most Down call
in the Top portion.
-If not found, then it determines next the upper most Down call in
the Bottom portion.
-If not Found, then it determines the next the lower most Up call
in the Bottom portion.
-If not found, the lift stops.
-If lift is going Down, it first determines if floor number of the
upper most Down call in the Bottom portion,
-If not found, then it determines next the lower most Up call
in the Bottom portion.
-If not found, then it determines next the lower most Up call in
the Top portion.
-If not Found, then it determines the next the upper most Down call in the Top portion.
-If not found, the lift stops.
-If the lift is moving Up and all selections of FloorToGo that are lower than the value of liftFloor made by the internal passenger are ignored, and vice versa.
-When an external passenger on a certain floor requests to go down but the lift is in Up motion to send someone to a floor above that of the external passenger's floor, it will not stop by on the external passenger's floor to pick the external passenger, and vice versa.
Here's where I need some help and advice:
1) I am required to write a menu function consisting of options
C(call lift from floor), S(select destination in lift) and
M(move lift).
I have no problem with the C option but the S option there is
a slight problem. Since the program can only ask which floor
the passenger wants to go, one way to decide whether
he/she is going up or down is to compare the floorLift and the
destination floor. Since floorLift is private how do I determine
in the S option whether to go Up or Down to satisfy the
parameter "m" in the CallTo() function?
2) The MoveLift function takes no parameters and returns an
integer. If no parameters are taken how do I go about telling
the function the conditions of lift movement based on the
lift alogarithm, when all the required information is in the
CallTo function? Or am I not using the function as intended??
3) If I were to register to the table Floor(adding a Up or Down at Floor[FloorToGo]) do I need to create a new function, or do i just register it in the CallTo function when the returned value is true?
4) Also if anyone could see if my alogarithm of the movement of the lift is correct, that would be great.
notes - Some situations not handled by this simulation would be:
a) Internal passenger destination coincides with the floor on which an external passenger is also making a request.
b) External passengers on the same floor requesting for the lift to go up and down simultaneously.
All help will be greatly appreciated.
Thanks in advance!