The George Washington University
School
of Engineering and Applied Science
Department of Computer Science

CSci 51 -- Introduction to Computing – Spring 2002

Lab #4
Feb. 7 & 8

Part I. The Basics
The purpose of this exercise is to give you practice working with arithmetic assignment statements. First, compute by hand what you except the values of int, nat, and flo will be for each arithmetic assignment statement below (see Section 3.6 in your textbook).

 
     int := 7 * 3 + 3 * 9;    --  Print with "Width => 4"
     int := 7 + 2 / 3 * 9;    --  Print with "Width => 4"
     int := 7 - 2 * 9 + 3;    --  Print with "Width => 1"    
 
     nat := 7 ** 2 * 3 + 9;   --  Print with "Width => 4"
     nat := 7 / 3 / 2 * 9;    --  Print with "Width => 1"
     nat := 7 / 3 / 2 - 9;    --  Print with "Width => 1" 
 
     flo := 36.0 / 6.0 * 1.5;        --  Print with "Fore => 4, Aft => 2"
     flo := 9.0 / 3.0 - 7.0 / 2.0;   --  Print with "Fore => 4, Aft => 2"

Second, use "vi" to create the program given below. Then, test each arithmetic assignment statement in the program given below, one at a time. The program is already written for the first arithmetic assignment statement. Print format instuctions are given as comments above.

 
     WITH Ada.Text_IO;
     WITH Ada.Float_Text_IO;
     WITH Ada.Integer_Text_IO;
     PROCEDURE lab_03 IS
          int : Integer;
          nat : Natural;
          flo : Float;
     BEGIN
          int := 0;  nat :=0;  flo := 0.0;
 
          Ada.Text_IO.put (Item => "int := 7 * 3 + 3 * 9; gives ");                                         
          int := 7 * 3 + 3 * 9;
          Ada.Integer_Text_IO.put (Item => int, Width => 4);
          Ada.Text_IO.new_line;
     END lab_03;                                       

Part II. Working with packages and enumeration types
You are to write a program that prompts the user for a date, then displays the day of the week on which that date occurs (e.g. SEP 24, 1992 is on a THURSDAY). Your output should look exactly like this example.

The month will be entered as a 3-letter enumeration literal (Jan, Feb, etc).

The day will be entered as an integer in the predefined subtype Ada.Calendar.Day_Number; the year will be entered as an integer in the predefined subtype Ada.Calendar.Year_Number.

To find the day of the week, use the package DayWeek in the programs directory. The specification is in dayweek.ads; the body is in dayweek.adb. This package is not in the book, but it is online in the programs directory. A simple program, DayTest, that demonstrates the package is in daytest.adb