The George Washington University
School of Engineering and Applied Science
Department of Electrical Engineering and Computer Science
CSci 51 -- Fall 1996
Project #8
Due Date: start of class, Nov. 14, 1996

This project involves an extension of the speed-monitoring program you did for Project 5. It depends on material from Chapter 7, especially random-number generation as shown in Random_Numbers (Program 7.6) and Drunken_Spider (Program 7.7), and the calendar operations in Time_of_Day (Program 7.1).

This program will be a simulation of a speed-monitoring session on the Beltway. Instead of creating a file full of data as in Project 5, consider that on the Beltway, cars pass a given point at random time intervals, going at more-or-less random speeds. With the Beltway speed limit set at 55, we can assume that almost all speeds lie between, say, 40 and 80. And at most times of the day, cars pass the monitoring equipment every few seconds.

Part 1:

You're going to develop a package that contains the speed types from Project 5, the speed-classification function, and a new function that will deliver a random speed. If this were a real speed monitor, this function would be connected to the radar gun instead of the random number generator. The specification of this package will look like this:

PACKAGE Speeds IS
 
  TYPE SpeedClasses IS (Class1, Class2, Class3, Class4, Class5);
  SUBTYPE Speeds IS Natural RANGE 0..130;
 
  FUNCTION Classify (Speed: Speeds) RETURN SpeedClasses;
  -- Pre: Speed is defined
  -- Post: Returns the class of the given speed
 
  FUNCTION DeliverSpeed RETURN Speed;
  -- Pre: None
  -- Post: Delivers a random speed in the range 40..80
 
END Speeds;

In the body of this package, put the function bodies as usual. Also, you will need to instantiate Ada.Numerics.Discrete_Random for the range 40..80. This instance, and the generator variable G, should appear at the top of the package body.

Part 2.

Now develop a main program, based on the one you wrote for Project 5, that simulates the speed monitor's operation for one hour beginning with the current time. Here you'll need a second instance of the random number generator, for the subtype

SUBTYPE ArrivalTimes IS Positive RANGE 1..60;

Call this instance RandomArrival, and the generator variable A. If T represents the time of day, then a new time is calculated by

T := T + Duration(RandomArrival.Random(Gen=>A));

For each new time, get a speed from DeliverSpeed, classify it, and display a line like:

THU NOV 7 1996 12:40:17: Speed 57, Class 3

At the end of about one hour in simulated time, display the speed statistics as you did in Project 5.