Worksheet Answers: Pseudocode and Flowcharts
Question 2(i): Changes to find the largest number
1. Change 'Small = 1000' to 'Large = 0'.
2. Change condition 'IF Num < Small THEN Small = Num' to 'IF Num > Large THEN Large = Num'.
3. Change 'PRINT Small' to 'PRINT Large'.
Question 2(ii): Modified Pseudocode
Large = 0
Counter = 0
REPEAT
INPUT Num
IF Num > Large THEN Large = Num
Counter = Counter + 1
UNTIL Counter = 10
PRINT Large
Question 3(i): Suitable Data Types
Name: String
Gender: Char
Status: String
Fee: Real (Float)
Team member: Boolean
Question 3(ii): Suitable Data Structure
Data Structure: Array of records
Reason: Allows organized storage of multiple members' details.
Question 4: Trace Table
Refer to the trace table provided in the original response.
Question 5: Loop Structures
1. WHILE...DO...ENDWHILE - Executes as long as condition is true.
2. FOR...TO...NEXT - Iterates a set number of times.
Question 6(a): Why No Primary Key?
Some staff members have the same name, department, and extension.
Question 6(b): Suggested Primary Key & Reason
Primary Key: Staff ID
Reason: Ensures uniqueness.
Question 6(c): Query-by-Example Grid
Field: Name, Department
Sort: ASC (Name)
Show: Yes
Question 7(a): Purpose of FOR Loop
Iterates 300 times to take 300 names as input.
Question 7(b): Alternative WHILE Loop
I=1
WHILE I <= 300 DO
INPUT Name[I]
I=I+1
ENDWHILE
Question 7(c): Input Validation Pseudocode
REPEAT
PRINT 'Enter a number between 0 and 100'
INPUT Num
IF Num < 0 OR Num > 100 THEN
PRINT 'Error! Invalid number.'
ENDIF
UNTIL Num >= 0 AND Num <= 100
Question 8(a): Error in Pseudocode
Error: UNTIL Count > 100
Correction: UNTIL Count = 100
Question 8(b): Improved Algorithm Using WHILE Loop
Count = 0
Sum = 0
WHILE Count < 100 DO
INPUT Number
Sum = Sum + Number
Count = Count + 1
ENDWHILE
PRINT Sum
Question 9(a): Why the Algorithm Never Ends
Error: UNTIL Count = 0 (Condition never met).
Correction: UNTIL Count = 50
Question 9(b): Store Only Numbers >=100
Count = 0
REPEAT
INPUT Num
IF Num >= 100 THEN
Values[Count] = Num
Count = Count + 1
ENDIF
UNTIL Count = 50
Question 9(c): Prevent Numbers <100 and >200
IF Num >= 100 AND Num <= 200 THEN
Values[Count] = Num
Question 10(a): Validation vs. Verification
Validation: Ensures data is reasonable (e.g., range checks).
Verification: Ensures data is correct (e.g., double entry).
Question 10(b): Data Verification Example
Double entry of passwords for accuracy.
Question 10(c): What is a Library Routine?
Pre-written function used in programs (e.g., Math.sqrt()).
Question 11(a): Describe Given Pseudocode
Takes 12 inputs, calculates sum and average.
Question 11(b): Modify to Allow Any Number of Inputs
Sum = 0
Count = 0
REPEAT
INPUT Num
Sum = Sum + Num
Count = Count + 1
PRINT 'Enter -1 to stop'
UNTIL Num = -1
PRINT 'Average: ', Sum / Count
Question 12(a): Validation Checks Matching
Range check: Checks if a value is within a limit.
Presence check: Ensures data is entered.
Length check: Limits number of characters.
Type check: Ensures correct data type.
Question 12(b): Counting and Totalling Example
TotalWeight = 0
BasketCount = 0
REPEAT
INPUT BasketWeight
TotalWeight = TotalWeight + BasketWeight
BasketCount = BasketCount + 1
UNTIL BasketCount = 10
PRINT TotalWeight
Question 13(a): Name of Statement Type
Nested IF Statements
Question 13(b): Rewrite Using CASE Statement
CASE Response OF
1: X = X + Y
2: X = X - Y
3: X = X * Y
4: X = X / Y
OTHERWISE: PRINT 'No response'
ENDCASE