This is a closed-book 62-point exam. Write your answers in the bluebook. If you want to put an answer on the exam itself, say so in the bluebook and put your name on the exam. Explain your answers clearly.
program corn(output); var a, b : integer; procedure wheat( a : integer ); begin a := 1 end; procedure oats( var c : integer; d : integer ); begin c := 2; d := 3 end; procedure quatrotriticale( var e, f : integer ); var temp : integer; begin temp := e; e := e - f; f := temp end; begin a := 4; b := 5; wheat( b ); writeln( 'First: ', a, b ); a := 4; b := 5; oats( a, b ); writeln( 'Second: ', a, b ); a := 4; b := 5; quatrotriticale( b, a ); quatrotriticale( a, b ); writeln( 'Third: ', a, b ) end.
5 little ducks went out one day Over the hills and far away Mother duck said, "Quack quack quack quack" But only 4 little ducks came back 4 little ducks went out one day ... 1 little duck went out one day Over the hills and far away Mother duck said, "Quack quack quack quack" But none of the 5 little ducks came back
Your task is to write a procedure to print out the lyrics of this song, starting with any number of ducks, like so:
{ Ducks prints the lyrics of the song starting with N ducks. } procedure Ducks( N : integer );
By the way, the song does have a happy ending, but you may leave the poor mother duck in limbo.
for i := 1 to 3 do for j := i to 3 do writeln( i, j );
{ IsCharInWord returns true if the character ch is equal to any of the characters word[1], word[2], ..., word[length], and false otherwise. } function IsCharInWord( ch : char; word : charArray; length : integer ) : boolean;
Note that this function should contain no read, write, readln, or writeln calls.
The type charArray is defined by
type charArray = array[1..100] of char;