passenger.h

 
# define maxPassenger 9

class Passenger
{
public:
    /* default constructor initialize that the elevator is empty           */
    Passenger()
    {
     curPassenger=0;   outPass=0;    inPass=0;
    }
   
    /* function for generating random number of passengers enter elevator  */
    void Enter( int );
   
    /* function for generating random number of passengers exit elevator   */
    void Exit( int );
   
    /* member function to check if the elevator is full or not             */
    bool Full();
   
    /* member function to check if the elevator is empty or not            */
    bool Empty();

protected:
    int curPassenger,    // current passenger in the elevator
        outPass,         // number of passenger exit
        inPass;          // number of passenger enter
};

void Passenger :: Enter( int xpos )
{
  srand(time(NULL));
  inPass = 1 + rand()% maxPassenger; // generate random number passenger enter
  int current = curPassenger;
  curPassenger += inPass;            // add to current passenger
 
  if ( Full() )                      // if passenger number reach maximum
  {
       inPass = maxPassenger - current;
       curPassenger = maxPassenger;
       gotoxy(xpos, 16);  cout<< inPass;
       gotoxy(xpos, 13);  cout<< curPassenger;
       gotoxy(xpos, 19);  cout<< " ";
  }
  else
  {
      gotoxy(xpos, 16);  cout<< inPass;
      gotoxy(xpos, 13);  cout<< curPassenger;
      gotoxy(xpos, 19);  cout<< " ";
  }
}

void Passenger :: Exit( int xpos )
{
     srand(time(NULL));
     outPass = 1 + rand()%curPassenger;       // generate random passenger exit
     if ( curPassenger == 1 )  outPass = 1;   // one passenger set exit

     curPassenger -= outPass;

     gotoxy(xpos, 19);  cout<< outPass;
     gotoxy(xpos, 13);  cout<< curPassenger;
     gotoxy(xpos, 16);  cout<< " ";
}

bool Passenger :: Full ()  {  return curPassenger >= maxPassenger;   }

bool Passenger :: Empty () {  return curPassenger <= 0;   }

Project Homepage: