The George Washington University
School of Engineering and Applied Science
Department of Electrical Engineering and Computer Science
CSci 51 -- Spring 1999
Project #6
Due Date: start of class, March 25, 1999

Many states have recently raised the speed limits on some of their highways. The state police would like to collect statistical data on the actual speeds of cars under the new laws, and have hired us to develop a computer program to help them. Unfortunately, the police did not give us a real radar unit to test our program, so we will have to get along with a simulation. Simulations are a very important application of software!

This project will be a simulation of a speed-monitoring session on the Beltway. 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.

  • Class 1: 0 < speed<= 45 miles per hour (m.p.h.)
  • Class 2: 45 < speed <= 55
  • Class 3: 55 < speed <= 65
  • Class 4: 65 < speed <= 75
  • Class 5: 75 < speed

First develop the body of a package that contains several types; a speed-classification function; and a procedure that will deliver a random speed at a random time. If this were a real speed monitor, this procedure would be connected to the radar gun instead of the random number generator. The specification of this package will look like this:

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

In the body of this package, put the subprogram bodies as usual. Also, you will need to instantiate Ada.Numerics.Discrete_Random for the speeds and time intervals. These instances, and the generator variable G, will appear at the top of the package body.

Now develop a main program that simulates the speed monitor's operation for the first 200 arriving cars. The main program will keep track of the elapsed time, starting from 0, and call DeliverSpeed repeatedly. Keep running totals of the number of cars in each speed category.

For each arriving car, classify its speed, and display the elapsed time, speed, and speed class, like this:

Time 27, Speed 57, Class 3

Finally, at the end of the run, display the total number of cars in each speed category.