Download a ZIP'ed copy of the Lab 10 project and store it in the C:\FILES directory.
Go into the MS-DOS prompt and execute the following commands:
The only files you'll modify in this lab are
stoplite.h
and stoplite.cpp
which define a class called StopLight
.
StopLight
is a representation of a traffic signal.
The traffic signal controls the crossing of two roads,
one running North-South and another running East-West.
It has several methods,
specified in stoplite.h,
that are used to modify and
examine the traffic signal.
Start by looking at StopLight's include file stoplite.h to see its internal variables. There are only three:
time
stateNS
stateEW
stateNS
and stateEW
are Go
, Caution
, and Stop
.
Now let's look at the methods and constructors of StopLight. There is a single constructor with no arguments which should initialize the three private variable of StopLight.
StopLight::StopLight() { // You need to initialize stateNS here stateEW = Go ; time = 0 ; }Unfortunately, due to a bug, one of these variables is not initialized. You'll need to fix that.
Six methods control the bulbs
of the light. These methods have cryptic names that refer
to the bulb they control. For example,
method bulbNSR
is used to determine
if the red bulb in the North-South direction is turned on.
int StopLight::bulbNSR(void) { return stateNS == Stop ; }The definitions of a couple of the "bulb" methods are missing in stoplite.cpp. You'll have to fill them in.
Fix the constructor and write the missing bulb methods. You should now be able to build and run the program.
The method Tick
does all the interesting work.
It is to supposed be called once a second
from an outside time source. This method should, when
appropriate,
update internal variables of StopLight
so that traffic is controlled in an orderly fashion.
The way in which StopLight
is supposed
to be used in that once a second a call is made to
the Tick
method followed by calls to
the six bulb methods. However, because once a second
would be boring, our lab driver presently calls
ten times a second.
Carefully study the buggy code for the Tick method. Modify it so that it behaves like a normal traffic signal. A compiled example of a program that solves this problem is available. You'll need to save it into the C:\FIlES directory and then run it.
Now turn the stop light into a signal that blinks red in one direction and yellow in another. Again a compiled example is available. You'll probably want to change the definition of the enumerated type Signal by adding a new value in order to solve this problem.