Академический Документы
Профессиональный Документы
Культура Документы
Daniel wrote the program below to print the larger of two numbers, assuming that the two numbers
are not equal. When Daniel compiled the program there were SEVEN errors.
1
Program Largest
2
Var X; Y: char;
3
Begin
4
Input(X, Y);
5
If X < Y
6
Then Writeln (X is the larger number);
7
Else Writeln (Y is the larger number)
8
End;
(a)
Identify the line number of EACH error and rewrite the correct statement. (7 marks)
3.
[2 marks]
Complete the following table showing the expected output from the
flowchart for the three, independent, sets of input data. [5 Marks]
3.
4.
5.
To find root(12)
Pick a number that when squared, comes close to (but is less
than) the number whose square root youre finding: 3 3 = 9.
This is a better choice than 4: 4 4 = 16
Divide the number youre finding the square root of (12) by
the number you squared (3) in step 2: 12 3 = 4
Average the closest square root (3) and the answer of step 3
(4): 3 + 4 = 7. 7 2 = 3.5
Square the average to see how close the number is to 12:
[20 Marks]
Solutions
1.
1
2
3
4
5
6
7
8
Note: The program itself has a logic error in the output statements. This will not cause compilation errors.
2.
Possible solution:
Mark Scheme
program ATM;
CONST
dailyLimit: real = 2500;
Messages [2 marks]
VAR
BEGIN
currentBalance:=10000;
extraCharge: =0;
readln(amtRequest);
IF (amtRequest > currentBalance) THEN
writeln(The amount requested exceeds your current balance. Program terminated.)
ELSE
IF (amtRequest > dailyLimit ) THEN
writeln(Daily limit exceeded. Program terminated)
ELSE (* we can process a valid transaction *)
Begin
IF ( currentBalance < 100 ) THEN extraCharge : = amtRequest * chargeRate;
currentBalance:= currentBalance (amtRequest + extraCharge);
writeln(Withdrawal amount
Extra charges
Current Balance);
3.
INPUT X
48
9170
-800
OUTPUT S
2
4
1
4.
A
A OR B
A AND B
NOT(A OR B)
NOT(A AND B)
NOT(A)
NOT(B)
NOT(A) OR
NOT(B)
NOT(A) AND
NOT(B)
0
0
1
1
0
1
0
1
0
1
1
1
0
0
0
1
1
0
0
0
1
1
1
0
1
1
0
0
1
0
1
0
1
1
1
0
1
0
0
0
5.
INPUT
userNum
PROCESSING
OUTPUT
absError = 0.0001
initialPick = 0
REPEAT
initialPick = initialPick + 1
pickSq = initialPick* initialPick
UNTIL (pickSq >= userNum)
If(pickSq=userNum) then avgPick=initialPick
Else
Repeat
nextPick = usernum/initialPick
avgPick = (initialPick + nextPick) / 2
initialPick = avgPick
pickSq= avgPick * avgPick
error = userNum pickSq
if( error < 0) error:=error* (-1)
Until (userNum pickSq < absError)
STORAGE
absError: real
userNum: real
initialPick: real
nextPick: real
avgPick: real
pickSq: real
error: real