Coen 1
Fall 2000
Homework 4 Answers
Question1: array (-5..11) of integer;
Question1 [-5] := 15;
Foo := Question1 [1];
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;
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.
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).
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.
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.