Brock University
Department of Computer Science

COSC 3P95: Assignment 0 -- Ada Warm-Up

Instructor: Vlad Wojcik mail.gif (1189 bytes)


To acquaint students with each other, as well as with Ada 2005 programming techniques. This assignment is obligatory for all, although will not be marked. There is due date/time of 23 Sep 2013, 4 PM. The material and code of this assignment will be useful towards future assignments.

PROBLEM 1 (Tentative Team):

Form a tentative team of three persons, and together construct a MINDSTORM robot as intended by its manufacturer, LEGO, inc. The goal of this exercise is to enhance your interpersonal skills, to get to know your potential team mates, and to refresh your childish block manipulation skills, which probably faded a bit by now.

PROBLEM 2 (Individual):

Read the book "Vehicles" by Valentino Braitenberg with an eye towards ideas for an interesting robot to be created as your team project, at the end of the course.

PROBLEM 3 (Individual):

The file random.pas, reproduced below for your convenience, contains the code of an industrial-strength random number generator, written in Pascal, a direct ancestor of Ada.

PROGRAM Random(Output);
 CONST seed1 = 5; seed2 = 10000; seed3 = 3000;
 VAR x, y, z : integer;
     loop : integer;
 FUNCTION   Unif : real;
     Var tmp : real;
     Begin {Unif}
        x := 171*(x mod 177) - 2*(x div 177);
        if x<0 then x := x + 30269;
        y := 172*(y mod 176) -35*(y div 176);
        if y<0 then y := y + 30307;
        z := 170*(z mod 178) -63*(z div 178);
        if z<0 then z := z + 30323;
        tmp :=  x/30269.0 + y/30307.0 + z/30323.0;
        Unif := tmp - trunc(tmp)
     End;  {Unif}
     x := seed1; y := seed2; z := seed3;
     for loop := 1 to 1000 do
     writeln(loop:4, ' ==> ', unif:7:5)

The function Unif, being the random number generator, returns numbers seemingly of random nature, uniformly distributed within an interval [0, 1]. The value returned by Unif depends in a somewhat arcane way on three integer values x, y, z. These three values are declared outside the block defining the function Unif, and therefore retain their values between Unif calls. In this way Unif produces seemingly random, but reproducible number sequences.

At the very beginning of the program execution, x, y, z are given some seed values. Different seed values result in different, but reproducible, number sequences. This reproducibility is useful for debugging purposes; also, science demands that the results of every scientific experiment be reproducible.

Obtaining non-reproducible sequences is simple: the seed values should be established by perusing the system clock (accessible to Ada 2005 programmers via the package CALENDAR), prior to calling Unif for the first time.

You are to create an Ada 2005 package, called RANDOM, that would contain an equivalent random number generator, also called Unif. The users of the package should be able to call Unif, and also should be able to set the seed values if they wanted reproducible sequences. Let us adopt the convention that not passing any seed values before calling Unif amounts to the request for a non-reproducible number sequence.

The three values x, y, z should be hidden in the package body, following the canons of proper software engineering.

NOTE: The function trunc in Pascal takes a real argument and returns a real result, being the value of its argument with the fractional part truncated. {Curly braces like this contain comments}.

cameo.gif (1740 bytes)Instructor: Vlad Wojcikmail.gif (1189 bytes)
Revised: 9 September, 2013 5:29 PM
Copyright 2013 Brock University