Project 7

The George Washington University
School of Engineering and Applied Science
Department of Electrical Engineering and Computer Science
CSci 51 -- Spring 1997
Project #7
Due Date: start of class, Apr. 7, 1997

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

This program will be a simulation of a speed-monitoring session on the Capital Beltway. On this highway, cars pass a given point going at more-or-less random speeds.

Part 1:

To your speed package from Project 4, add 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 modified specification of this package will look like

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

You will need to instantiate Ada.Numerics.Discrete_Random for the range 0..130. 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 4, that collects and summarizes the speeds for 500 passing cars. (That is, ask your "radar gun" to deliver 500 speeds.) Keep track of the number of speeds in each of the five categories, and, at the end of the run, display your results numerically and in the form of a horizontal bar graph. A line in the bar graph will look like this, say, for 153 Class 3 speeds:

Class 3  153 ****************


Note that there are 16 asterisks: each asterisk represents ten speeds; if the number of speeds is not a multiple of ten, include one asterisk for the "extra" speeds.