Exercises for Week One.

Example One.

Produce documentation for the following Pascal Procedure, using pseudo-code, flow charts and BS6224 diagrams to describe the structure.

Procedure ChooseOption (Var choice:integer);
Begin
DISPLAYMENU
Readln (choice);
Case choice of 
1: OPTION1;
2: OPTION2;
3: OPTION3;
4: OPTION4;
5: Writeln(Exit Program);
End {of case statement};
End{ of procedure};

Note that other procedure names are given in capitals and you will need to comment on the interface with these procedures. Comments, which are ignored by the complier, appear with brackets { ---- }.

Within a Pascal procedure call, arguments to return values are preceded by the keyword “Var” and those which supply input data are not.


Example Two.

Produce documentation for the following Pascal Procedure, using pseudo-code, flow charts and BS6224 diagrams to describe the structure.

Procedure TransferRecord( Var Input:boolean; Var F1; File; Var NextRec: Record;
		Var OK;boolean);
Begin
 OK := “TRUE”;
If Input {= true} 
	THEN
	IF EOF(F1) 	THEN 
			OK := “FALSE”
			ELSE
			Read (F1, NextRec)
	ELSE 
	Write (F1,NextRec);
	End;

END { of procedure}; 

You may assume that EOF(filenumber) is a system routine which returns the value TRUE if the end-of-file has been reached and the value FALSE if it has not.


Example Three.

Produce documentation for the following Pascal Procedure, using pseudo-code, flow charts and BS6224 diagrams to describe the structure.

Procedure CompareCodes( guess,code:string; Var black,white:integer);

Var
G,C : array [1..4] of char;
i,j : integer;

Begin
For I := 1 to 4 do
	begin
	COPY(guess(i,i), G(i));
	COPY(code(i,i),C(I));
	end;
black := 0;
For i := 1 to 4 do
	IF C(i) = G(i) THEN
		Begin
		black := black + 1;
		G(i) := “x”;
		C(i) := “z”;
		End;

white := 0;
For i := 1 to 4 do
For j := 1 to 4 do
	IF C(i) = G(j) THEN 
		Begin
		white := white + 1;
		G(j) := “x”;
		C(i) := “z”;
		End;
END {of Procedure};