0% found this document useful (0 votes)
64 views

IGCSE_Pseudocode_Answers_Detailed

The document provides detailed pseudocode answers for IGCSE topics, focusing on arrays, procedures, functions, string manipulation, and file handling. It includes examples of algorithms like linear search and bubble sort, highlights common errors in pseudocode, and suggests improvements for clarity. Additionally, it explains the purpose of parameters and various string and file operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

IGCSE_Pseudocode_Answers_Detailed

The document provides detailed pseudocode answers for IGCSE topics, focusing on arrays, procedures, functions, string manipulation, and file handling. It includes examples of algorithms like linear search and bubble sort, highlights common errors in pseudocode, and suggests improvements for clarity. Additionally, it explains the purpose of parameters and various string and file operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Detailed IGCSE Pseudocode Answers

PART 1: ARRAYS

Q1.1

(a) Line Numbers for Statements:

- Assignment statement: These lines assign values to variables:


Line 3: Initializes the variable `Max` with the first element of the list.
Line 4: Initializes the variable `Min` with the first element of the list.
Line 7: Updates the value of `Max` if a larger number is found.
Line 8: Updates the value of `Min` if a smaller number is found.

- Selection statement: These lines involve decision-making processes:


Line 5: Checks if the current element is greater than `Max`.
Line 6: Checks if the current element is smaller than `Min`.

- Iteration statement: These lines control the loop for processing the list:
Line 2: Initializes and begins the loop that iterates through the list.
Line 9: Marks the end of the iteration process.

(b) Errors in Pseudocode:

- **Error 1:** Line 4


Correction: The pseudocode uses `Max ‹ List (Counter)`, which is incorrect.
Fix: Replace `‹` with `←`. Corrected line: `Max ← List(Counter)`

- **Error 2:** Line 7


Correction: The pseudocode uses `Min + List[Counter)`, which is a syntax error due to the
`+`.
Fix: Replace `+` with `←` and `[` with `(`. Corrected line: `Min ← List(Counter)`

- **Error 3:** Line 9


Correction: The pseudocode incorrectly uses `ENDWHILE`, which should match the `IF`
statement.
Fix: Replace `ENDWHILE` with `ENDIF`.
Q1.2

(a) Linear Search Algorithm in Pseudocode:

This algorithm searches for a specific number within an array of 50 integers. It uses a loop
to traverse the array and compares each element with the target number. If the number is
found, its position is output, and the loop terminates early.

Detailed Pseudocode:
DECLARE Values : ARRAY[1:50] OF INTEGER
DECLARE MyNumber : INTEGER
DECLARE Found : BOOLEAN
DECLARE Position : INTEGER

INPUT "Enter a number:", MyNumber


Found ← FALSE
FOR Counter ← 1 TO 50
IF Values[Counter] = MyNumber THEN
Position ← Counter
Found ← TRUE
OUTPUT "Number found at position ", Position
BREAK
ENDIF
NEXT Counter

IF NOT Found THEN


OUTPUT "Not found"
ENDIF

(b) Bubble Sort Algorithm in Pseudocode:

Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares
adjacent elements, and swaps them if they are in the wrong order. This process continues
until the list is sorted.

Detailed Pseudocode:
DECLARE Values : ARRAY[1:50] OF INTEGER
DECLARE Temp : INTEGER

FOR I ← 1 TO 49
FOR J ← 1 TO (50 - I)
IF Values[J] > Values[J + 1] THEN
Temp ← Values[J]
Values[J] ← Values[J + 1]
Values[J + 1] ← Temp
ENDIF
NEXT J
NEXT I

Q1.3

(a) Purpose of the Pseudocode Algorithm:

The purpose of this algorithm is to take a list of names as input, sort them in ascending
alphabetical order using a bubble sort algorithm, and then output the sorted list. This
ensures that the names are organized for further use or display.

(b) Four Processes in the Algorithm:

1. Inputting names from the user to populate the array.


2. Using nested loops to implement a bubble sort algorithm for sorting names.
3. Comparing and swapping adjacent names to ensure correct order.
4. Displaying the sorted list of names as the final output.

(c) Meaningful Identifiers Suggestions:

- Array: `Names` (to store the list of names)


- Variables:
`T` → `TotalNames` (to store the total number of names)
`L` → `Index` (to track the position during iteration)

(d) Ways to Improve Understandability:

1. Add comments to explain each section of the code and its purpose.
2. Use meaningful and descriptive variable names to make the logic clear.
3. Break down the sorting logic into a separate function or procedure for modularity.
4. Include error handling for invalid or empty inputs.

PART 2: PROCEDURES & FUNCTIONS

Q2.1
A **parameter** is a variable used to pass information between procedures or functions
and the main program.
Q2.2

Procedures and parameters enhance a program by:


1. Allowing for modular code that is easier to manage and debug.
2. Enabling the reuse of code blocks with different data inputs, reducing redundancy.
3. Improving readability and organization by separating logic into smaller units.

Q2.3

- **DIV:** Performs integer division, returning only the quotient. For example, 17 DIV 5
results in 3.
- **ROUND:** Rounds a real number to the nearest specified number of decimal places. For
example, ROUND(3.14159, 2) results in 3.14.

Q2.4

- **MOD:** Returns the remainder of integer division. For example, 17 MOD 5 results in 2.
- **RANDOM:** Generates a random number within a specified range. For example,
RANDOM(1, 10) generates a number between 1 and 10 inclusive.

Q2.5

When a function is called:


1. The program temporarily transfers control to the function.
2. The function executes its set of instructions.
3. A result may be returned to the calling point, and the program resumes execution from
where it left off.

PART 3: STRING FUNCTIONS & FILE HANDLING

Q3.1

- **String Manipulation:**
DECLARE FullText : STRING = "Computer Science"
DECLARE Substring : STRING

Substring ← SUBSTRING(FullText, 1, 8) // Extracts "Computer"


OUTPUT Substring
OUTPUT UCASE(FullText) // Outputs "COMPUTER SCIENCE"

- **File Handling:**
DECLARE FileHandle : FILE
OPEN FileHandle FOR WRITE AS "Subjects.txt"
WRITE FileHandle, Substring
CLOSE FileHandle

Q3.2

- **String Operations:**
DECLARE Quote : STRING = "Learning Never Exhausts The Mind"
DECLARE Extracted : STRING

Extracted ← SUBSTRING(Quote, 21, 8) // Extracts "The Mind"


OUTPUT Extracted
OUTPUT LCASE(Quote) // Outputs the string in lowercase

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy