beautypg.com

HP Integrity NonStop H-Series User Manual

Page 126

background image

bool canSeat (unsigned int numberOfPeople);
void order(unsigned int numberOfScoops);
void leave(unsigned int numberOfPeople);

private:
unsigned int freeChairs;
double profit;
} theSimulation;

There are three basic activities associated with the store. These are arrival, ordering and eating, and leaving.
This is reflected not only in the three member functions defined in the simulation class, but in three
separate subclasses of event.

The member functions associated with the store simply record the activities taking place, producing a log
that can later be studied to evaluate the simulation.

bool storeSimulation::canSeat (unsigned int numberOfPeople)
// if sufficient room, then seat customers
{
cout << "Time: " << time;
cout << " group of " << numberOfPeople << " customers arrives";
if (numberOfPeople < freeChairs) {
cout << " is seated" << endl;
freeChairs -= numberOfPeople;
return true;
}
else {
cout << " no room, they leave" << endl;
return false;
}
}

void storeSimulation::order (unsigned int numberOfScoops)
// serve icecream, compute profits
{
cout << "Time: " << time;
cout << " serviced order for " << numberOfScoops << endl;
profit += 0.35 * numberOfScoops;
}

void storeSimulation::leave (unsigned int numberOfPeople)
// people leave, free up chairs
{
cout << "Time: " << time;
cout << " group of size " << numberOfPeople <<
" leaves" << endl;
freeChairs += numberOfPeople;
}

As we noted already, each activity is matched by a subclass of event. Each subclass of event includes an
integer data field, which represents the size of a group of customers. The arrival event occurs when a group

This manual is related to the following products: