CLASS EXERCISE
- Determine the program output
- Draw a table illustrating the memory contents of array
test_times after initilisation.
program RECORD_TEST (output);
type time = RECORD
hours, minutes, seconds : integer
END;
procedure timeupdate ( var newtime : time );
begin
newtime.seconds := newtime.seconds + 1;
if newtime.seconds = 60 then
begin
newtime.seconds := 0;
newtime.minutes := newtime.minutes + 1;
if newtime.minutes = 60 then
begin
newtime.minutes := 0;
newtime.hours := newtime.hours + 1;
if newtime.hours = 24 then
newtime.hours := 0
end
end
end;
var test_times : array [1..3] of time;
loop : integer;
begin
test_times[1].hours := 11;
test_times[1].minutes := 59;
test_times[1].seconds := 59;
test_times[2].hours := 12;
test_times[2].minutes := 0;
test_times[2].seconds := 0;
test_times[3].hours := 1;
test_times[3].minutes := 29;
test_times[3].seconds := 59;
for loop := 1 to 3 do
begin
writeln('Time is ',test_times[loop].hours,':',
test_times[loop].minutes,':',test_times[loop].seconds);
timeupdate(test_times[loop]);
write('One second later its ');
writeln(test_times[loop].hour,s':',test_times[loop].minutes,
':',test_times[loop].seconds)
end
end.
Class Exercise..Program output is,
Time is 11:59:59
One second later its 12:0:0
Time is 12:0:0
One second later its 12:0:1
Time is 1:29:59
One second later its 1:30:0
Table illustrating array test_times contents after initialisation,
|---------------|<---------- -------------
| 11 | hours | |
|---------------| | |
| 59 | minutes |- Element 1 |
|---------------| | |
| 59 | seconds | |
|---------------|<---------- |
| 12 | hours | |
|---------------| | |
| 00 | minutes |- Element 2 |-- test_times
|---------------| | |
| 00 | seconds | |
|---------------|<---------- |
| 01 | hours | |
|---------------| | |
| 29 | minutes |- Element 3 |
|---------------| | |
| 59 | seconds | |
|---------------|<---------- -------------
Copyright B Brown/P Henry/CIT, 1988-1997. All rights reserved.