Coen 1

Fall 2000

 

Homework 4 Answers

  1. Consider the following array declaration in Pascal. Write a Pascal assignment statement to set the first element of the array to 15. Write a Pascal assignment statement to set a variable Foo to the value of the seventh element of the array.
  2. Question1: array (-5..11) of integer;

    Question1 [-5] := 15;
    Foo := Question1 [1];

  3. Consider the following record declaration in Pascal. Write a Pascal assignment statement to set Calories_Consumed to 101.3.
  4. Training_Run: record
    Distance: real;
    Time: real;
    Effect: record
    Calories_Consumed: real;
    Felt_Good: boolean;
    End;
    Month: integer;
    Day: integer;
    Year: integer;
    End;

    Training_Run.Effect.Calories_Consumed := 101.3;

  5. How many times does the following Pascal loop execute (how many values for Quant are printed out by the writeln statement)? The writeln statement is just a mechanism to print values out on the screen of the computer.
  6. Quant := 1;
    Ctr := -5;
    while Ctr < 10 do
    begin
    if (Ctr < 0)
    then Quant := Quant * 10;
    writeln (Quant);
    Ctr := Ctr + 2
    end;

    The loop starts executing with Ctr = -5 and Quant = 1. Since -5 < 10 the loop body is executed, and since -5 < 0 Quant becomes 10 and is printed (1st time). Then Ctr becomes -3. -3 < 10, so execute the loop again, -3 < 0 so Quant becomes 100 and is printed (2nd time). Then Ctr becomes -1. -1 < 10 so execute the loop, -1 < 0 so Quant becomes 1000 and is printed (3rd time). Then Ctr becomes 1. 1 < 10 so execute the loop, but 1 > 0, so don't change Quant. Print Quant for the 4th time, then Ctr becomes 3. Continue to execute the loop, not changing Quant, with Ctr equal to 3, 5, 7 and 9, printing a value for Quant 8 times. Then Ctr becomes 11 and the loop stops.

  7. How many times does the following Pascal loop execute?
    Sum := 0:
    for I := 6 to 20 by 3 do
    Sum := Sum + I;
    writeln (Sum);
  8. The loop body will execute with I having values 6, 9, 12, 15, 18 (5 times). When I has value 21 the loop is not executed, and the value for Sum is printed (60).

  9. Why is a compiler referred to as a "translator?"
  10. A compiler is referred to as a translator because it translates a program from the source language more easily understood by the human who developed the program into a binary machine language understood by a human. This is exactly analogous to translating English to Icelandic.

  11. How can the evolutionary software development model sometimes produce software systems that satisfy customer needs at less cost and in less time than other methods?

Because customers in the evolutionary development model are using the software for actual work at various stages in its development, they better understand what the software does and can more precisely direct programmers to add the capabilities they need (as opposed to want, or think they want). So only the features that are necessary become part of the software, saving development time and money.