1/12
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which keyword replaces a final CASE condition to catch anything unmatched?
OTHERWISE
What are the general steps to output the last 3 lines of a file, in order?
Open file for reading
Loop until end of file
Read line into a temporary variable
Shift previous values: LineX ← LineY
, LineY ← LineZ
Assign new line: LineZ ← ThisLine
Close file
Output LineX, LineY, LineZ
Why are the variables shifted (LineX ← LineY, etc.) when reading a file?
To ensure that only the last three lines are stored, in the correct order for final output.
How can you modify a file-reading algorithm to output 3 lines starting from a specific line number?
Loop until you reach the starting line (check for EOF and return FALSE if reached early)
Then read 3 lines (again, return FALSE if EOF is reached too soon)
Output each line
Return TRUE if successful
What type of error occurs when a program runs but crashes due to bad input? Give a cause.
Type: Run-time error
Cause: Invalid input or action, e.g., division by zero or converting a non-numeric string to a number.
Give one reason to use a module for repeated logic and state what this avoids.
Reason: Makes the program easier to test, debug, and maintain — change logic in one place only.
Avoided: Code duplication and inconsistent logic across the program.
Match these activities to their life cycle stages:
Activity | Life Cycle Stage |
---|---|
Interview client about system | |
Write code | |
Define records/files | |
Use walkthrough method | |
Modify for new hardware |
Activity | Life Cycle Stage |
---|---|
Interview client about system | Analysis |
Write code | Coding |
Define records/files | Design |
Use walkthrough method | Testing |
Modify for new hardware | Maintenance |
What type of testing is done on individual modules before combining them?
Integration testing (when combining modules)
Unit testing (if testing a single function on its own before integration)
(Note: Mark scheme said “integration,” but if the function is tested before combining, it’s “unit.”)
Give two advantages of using arrays instead of multiple selection statements.
Fewer lines of code — cleaner, shorter logic.
Easier to modify or maintain — values are stored in a single location and can be accessed using indexes.
What are the key components to include when drawing a structure chart for a program with subroutines?
Show all modules in the correct hierarchy (e.g., top-down: main procedure → subroutines)
Include parameters for each call (use arrows or labels)
Show return values from functions
Use curved arrow to represent repetition or recursion
Connect modules using single lines (not multiple arrows)
If a file needs to be updated by adding data (not overwritten), what must change?
Open the file in APPEND mode instead of WRITE mode
What is a local variable?
A variable declared inside a subroutine
Can only be accessed and used within that subroutine
Give one reason to use local variables in subroutines.
Prevents conflicts with variables in other parts of the program
Makes subroutines more modular, self-contained, and easier to debug