Source Module Module2C - HP nld Manual

Table of Contents

Advertisement

Sample nld and noft Session

Source Module MODULE2C

Source module MODULE2C contains the add_passengers and
delete_passengers functions. The add_passengers function checks to see if the
current number of passengers on the bus plus the number of passengers at the bus
stop exceeds the capacity of the bus. If so, the add_passengers function reduces the
number of passengers at the bus stop by the number of passengers that will fit on the
bus and sets the number of passengers on the bus to the maximum number, max. If
the bus has room for all of passengers at the bus stop, the add_passengers function
adds the number of people at the bus stop to the number of passengers on the bus
and sets number of people remaining at the bus stop to zero.
The delete_passengers function deletes a random number of passengers from the
bus. The random number is the result of the rand function bitwise-ANDed to the
hexadecimal number 0x7F, and is in the range from 0 through 127. If the random
number (which represents the number of people leaving the bus) is greater than the
number of passengers on the bus, the rand function is called until it returns a value in
the desired range.
Example A-7. Source Module MODULE2C With Edit Line Numbers
1
#pragma nolist
1.1
#include <stdlibh>
1.2
#pragma list
1.3
#include "globals.h"
1.5
5
void add_passengers(long bus_stop)
6
{
6.01
long bus_stop_passengers = bus_stop_array[bus_stop];
6.1
7
if (passengers_on_bus + bus_stop_passengers > BUS_CAPACITY)
8
{
8.001
8.01
8.02
8.1
}
9
else
9.01
{
9.1
9.11
9.2
}
10
} /* add_passengers */
11
12
void delete_passengers(long bus_stop)
13
{
14
15
16
16.01
16.1
16.2
17
} /* delete_passengers */
bus_stop_passengers -= (BUS_CAPACITY - passengers_on_bus);
passengers_on_bus = BUS_CAPACITY;
bus_stop_array[bus_stop] = bus_stop_passengers;
passengers_on_bus += bus_stop_passengers;
bus_stop_array[bus_stop] = 0;
long passengers_leaving;
passengers_leaving = 0x7F & rand();
while (passengers_leaving > passengers_on_bus)
passengers_leaving = 0x7F & rand();
passengers_on_bus -= passengers_leaving;
nld and noft Manual—520384-003
A- 5
Source Module MODULE2C

Advertisement

Table of Contents
loading

This manual is also suitable for:

Noft

Table of Contents