Thread: Newbie working on a lift simulation

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    Unhappy Newbie working on a lift simulation

    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!

  2. #2
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    >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?

    I'm not sure if this is what you need without seeing your class definition, but the easiest way to access a private class member is to create a public method that accesses the private member. So when you need to view or set the value of the private member you can call the method to do it.

    >The MoveLift function takes no parameters and returns an
    integer.

    The way I see it this method needs parameters. If you have to determine what floor to go to and what direction to go to get there then the MoveLift method has to have at least two parameters, direction and floor number.

    >Also if anyone could see if my alogarithm of the movement of the lift is correct, that would be great.

    You could simplify it a bit.
    -if lift is not moving, determine floor
    -if floor is greater than selection, go down; else go up
    -count down or up accordingly until the selected floor is reached
    -if lift reaches floor[top_floor] or floor[0] then stop

    I'm not sure if this is what you want, so please bear with me
    pointer = NULL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-07-2009, 11:31 AM
  2. Max/min function not working correctly
    By En-Motion in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2009, 12:28 AM
  3. Role of c++ in simulation software
    By CChakra in forum C++ Programming
    Replies: 9
    Last Post: 11-18-2008, 02:36 AM
  4. Help with time simulation assignment
    By rakan in forum C++ Programming
    Replies: 3
    Last Post: 10-31-2006, 11:39 AM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM