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

CSci 51 -- Introduction to Computing -- Fall 2001

Lab #4
September 18 and 19, 2001

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. Selecting a Data Type
What data type (integer, natural, or float) would you use to write a program to convert Fahrenheit to Celsius? The formula is below.

     Celsius = (5/9) * (Fahrenheit - 32)