0% found this document useful (0 votes)
5 views5 pages

Algorithm PS Solutions

The document contains model answers for various programming tests, covering topics such as output shapes, test data, abstraction, pseudocode, validation checks, and error identification. Each test includes specific questions and answers related to algorithms, data validation, and programming concepts. The answers are structured in a way that demonstrates understanding of fundamental programming principles and practices.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Algorithm PS Solutions

The document contains model answers for various programming tests, covering topics such as output shapes, test data, abstraction, pseudocode, validation checks, and error identification. Each test includes specific questions and answers related to algorithms, data validation, and programming concepts. The answers are structured in a way that demonstrates understanding of fundamental programming principles and practices.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Model Test 1: The Vending Machine (Model Answers)

(a) Shape for output [1 mark]

A parallelogram.

(b) Test Data [2 marks]

• Abnormal data: 100 (or -5, or "Ten")

• Extreme data: 5 (or 50)

(c) Abstraction and Decomposition [3 marks]

Abstraction is keeping the key elements required for the solution to a problem and
discarding any unnecessary details. Decomposition is breaking down a complex problem
into smaller, manageable parts that can be solved easily. Both are used to make complex
problems easier to understand and solve.

(d) Pseudocode for Totalling [4 marks]

Code snippet

Total <- 0

FOR Snack <- 1 TO 5

INPUT Price

Total <- Total + Price

NEXT Snack

OUTPUT Total

Model Test 2: The Weather Station (Model Answers)

(a) Validation Check [1 mark]

A Range Check.

(b) Boundary Data [2 marks]

• 50 (Accepted)

• 51 (Rejected)
(c) Max/Min Logic Error [3 marks]

If all the recorded temperatures that day are above 0°C (for example, a hot summer day),
the algorithm will falsely output 0 as the lowest temperature because the MinimumTemp
variable will never be updated. To fix this, MinimumTemp should be initialized to the value
of the very first temperature inputted, rather than 0.

(d) Pseudocode for Counting with a Sentinel [4 marks]

Code snippet

Count <- 0

REPEAT

INPUT Temp

IF Temp <> -99 THEN

Count <- Count + 1

ENDIF

UNTIL Temp = -99

OUTPUT Count

Model Test 3: The Library Kiosk (Model Answers)

(a) Search Algorithm [1 mark]

Linear Search.

(b) Double Entry [2 marks]

This is an example of Verification. It is used to ensure the student did not accidentally make
a typographical error (a typo) when entering their new PIN code.

(c) WHILE vs REPEAT [3 marks]

A WHILE...DO loop is a pre-condition loop, meaning it checks the rule at the very
beginning. If the condition is false right from the start, the loop might never run at all. A
REPEAT...UNTIL loop is a post-condition loop, meaning it checks the rule at the end, which
guarantees the actions inside the loop will always be completed at least once.

(d) CASE OF Pseudocode [4 marks]


Code snippet

CASE OF Category

"F" : OUTPUT "Fiction"

"N" : OUTPUT "Non-Fiction"

"R" : OUTPUT "Reference"

OTHERWISE OUTPUT "Unknown"

ENDCASE

Model Test 4: The Rollercoaster (Model Answers)

(a) System Design [1 mark]

Stepwise Refinement.

(b) System Pillars [2 marks]

(Any two of the following): Inputs, Processes, Outputs, Storage.

(c) Trace Table [3 marks]

Tickets OUTPUT

5 5

3 3

1 1

-1

(d) WHILE Loop Pseudocode [4 marks]


Code snippet

INPUT Password

WHILE Password <> "Secret123" DO

OUTPUT "Access Denied"

INPUT Password

ENDWHILE

Model Test 5: The Master Challenge (Model Answers)

(a) Ending Digit [1 mark]

A Check Digit.

(b) Validation Checks [2 marks]

• Type check (to ensure there are no alphabetical letters).

• Length check (to ensure it is exactly 10 characters long).

(c) Finding Errors [3 marks]

1. The line Total <- Total + Counter is wrong because it is adding the loop counter (1, 2,
3...) instead of the inputted Score.

2. The OUTPUT Total command is inside the loop, meaning it will print the running total
10 times instead of just printing the final total once at the end.

3. The loop is incorrectly closed with NEXT Score instead of NEXT Counter.

(d) Pseudocode for Counting a Specific Condition [4 marks]

Code snippet

Count <- 0

FOR Student <- 1 TO 20

INPUT Score

IF Score > 80 THEN

Count <- Count + 1


ENDIF

NEXT Student

OUTPUT Count

You might also like