Computer Science 9618/21 — October/November 2022
Cambridge AS Level · Fundamental Problem-solving and Programming Skills · worked solutions for every part, with the mark scheme
Topics Programming · Data Types and Structures · Algorithm Design and Problem-solving · Software Development
Refer to the insert for the list of pseudocode functions and operators.
An algorithm includes a number of complex calculations. A programmer is writing a program to implement the algorithm and decides to use library routines to provide part of the solution.
State three possible benefits of using library routines in the development of the program.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
Answer
- Development is quicker because the programmer does not need to write the routine from scratch.
- Library routines are usually already tested/debugged, so the program is likely to contain fewer errors.
- They are often well-optimised/standard routines, making the program easier to maintain and use reliably.
See explanation
Background Concept
A library routine is a pre-written piece of code supplied for programmers to use instead of creating that code themselves. Libraries often contain common tasks such as mathematical processing, string handling, file handling, or other standard operations.
In programming, reuse is important. If a routine has already been written, tested and documented, it is usually better to use it than to recreate it. This reduces development effort and can improve program quality.
Understanding the Question
The question says the algorithm includes complex calculations and the programmer decides to use library routines for part of the solution. You are not being asked to name a routine. You are being asked for three benefits of using library routines during development.
So the answer should focus on why pre-written routines help the programmer and the finished program.
Approach
Think of the main software-development advantages of reusing existing code:
- it saves time,
- it reduces errors because the code has already been tested,
- it can improve quality or maintenance because standard routines are reliable and well known.
Any three distinct valid benefits gain the marks.
Step-by-Step Reasoning
A good first point is about speed of development. If the programmer uses a library routine, they do not have to design and code that part themselves. That directly reduces development time.
A second strong point is about reliability. A library routine is normally pre-tested and debugged. That means there is less chance of introducing new logic or syntax errors compared with writing a fresh routine from scratch.
A third point can focus on code quality and maintenance. Standard library code is often well documented and optimised. This makes the finished program easier to maintain and usually more dependable.
So three valid answers are:
- saves development time,
- fewer errors because the code is already tested,
- easier maintenance / improved reliability / use of well-optimised standard code.
Key Takeaways
- Library routines are reused pre-written code.
- Main benefits are speed, reliability and maintainability.
- In theory questions, give distinct benefits rather than repeating the same idea in different words.
Common Mistakes
- Saying only "it is easier" without explaining why. The mark is for the benefit, such as saving time or reducing errors.
- Repeating the same point three times, for example "faster", "quicker", and "saves time".
- Giving a feature instead of a benefit, such as "it is in a library". That does not explain the advantage.
Things to Be Careful About
- The question asks for benefits of using library routines in development, so keep the answer about software creation and program quality.
- Make sure each point is different enough to earn a separate mark.
- Avoid over-specific examples unless they clearly support the benefit.
The following pseudocode is part of a program that stores names and test marks for use in other parts of the program.
DECLARE Name1, Name2, Name3 : STRING
DECLARE Mark1, Mark2, Mark3 : INTEGER
INPUT Name1
INPUT Mark1
INPUT Name2
INPUT Mark2
INPUT Name3
INPUT Mark3
The pseudocode needs to be changed to allow for data to be stored for up to 30 students.
Explain why it would be good practice to use arrays to store the data.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.....................................................................................................................................
Answer
- Arrays allow many student names and many marks to be stored under one identifier for each data type, using an index.
- The same index can refer to the matching name and mark for one student.
- The data can then be processed using loops, so the program is shorter, easier to amend for 30 students and easier to maintain.
See explanation
Background Concept
An array stores multiple items of the same data type under one identifier. Each item is accessed by an index, such as Name[1], Name[2], Name[3] and so on.
Arrays are useful when a program handles many similar values. Instead of creating separate variables like Name1, Name2, Name3, you can use one structure and change only the index. This makes programs easier to write, read and process with loops.
Understanding the Question
The original pseudocode stores three students using separate variables:
Name1,Name2,Name3Mark1,Mark2,Mark3
The question says the program must now store data for up to 30 students. You are asked why using arrays would be good practice.
So the answer should explain why arrays are a better design than creating 30 separate name variables and 30 separate mark variables.
Approach
Focus on the practical advantages of arrays in this situation:
- they store repeated data neatly,
- they let corresponding values line up by index,
- they make input, output and processing possible with loops,
- they reduce repetition and make the program easier to change.
Step-by-Step Reasoning
If separate variables were used, the programmer would need a long list such as Name1 to Name30 and Mark1 to Mark30. That is repetitive and difficult to manage.
With arrays, the programmer can declare something like:
Name[1:30]Mark[1:30]
Now all names are stored in one array and all marks in another. Each student can be matched by using the same index. For example:
Name[5]is the fifth student's nameMark[5]is the fifth student's mark
This is especially useful because the program can use a loop to input, search, total or display the values. Without arrays, the programmer would have to repeat similar code many times.
That is why arrays are good practice here: they reduce repeated code, keep related data organised, and make the program much easier to extend and maintain.
Key Takeaways
- Use arrays when storing many items of the same kind.
- An index identifies which item is being accessed.
- Arrays work naturally with loops, making code shorter and easier to maintain.
Common Mistakes
- Saying arrays can store different data types in one array. In standard pseudocode, one array stores one data type.
- Forgetting that names and marks would normally be stored in separate arrays because one is
STRINGand the other isINTEGER. - Giving only one vague reason such as "arrays are better" without explaining indexing or loop processing.
Things to Be Careful About
- The benefit is not just storage; it is also easier processing.
- Mentioning that the same index links a student's name and mark is a strong point.
- Do not describe records unless the question specifically asks for them; this question is about why arrays are better than many separate variables.
The following pseudocode statement includes array references:
OUTPUT "Student ", Name[Count], " scored ", Mark[Count]
State the purpose of the variable Count and give its data type.
Purpose .............................................................................................................................
...........................................................................................................................................
Data type ...........................................................................................................................
Answer
- Purpose:
Countis the index/subscript used to select which student'sNameandMarkare being output. - Data type:
INTEGER
Purpose: index/subscript for the current student; Data type: INTEGER
Background Concept
In an array, the index (or subscript) tells the program which position to access. For example, in Name[Count], the value of Count decides which name is used.
Index values are numeric, so the variable used as an index must be an integer. In many programs, this variable is also used as a loop counter when processing each item in turn.
Understanding the Question
The statement is:
OUTPUT "Student ", Name[Count], " scored ", Mark[Count]
You are asked two things about Count:
- what it does in this statement,
- what data type it must be.
Because Count appears inside square brackets for both arrays, it is being used to access a particular element from each array.
Approach
Look at where the variable appears. A variable inside array brackets is acting as the array index. Then identify the correct type for an index variable: INTEGER.
Step-by-Step Reasoning
Name[Count] means "take the value from the Name array at position Count".
Mark[Count] means "take the value from the Mark array at position Count".
Using the same index in both arrays means the name and mark belong to the same student. So the purpose of Count is to identify which student record is currently being output.
Since array positions are numbered, Count must be an integer. A real value such as 2.5 would not make sense as an array position.
Key Takeaways
- A variable inside
[]is being used as an array index. - Array indices are integers.
- The same index can be used across parallel arrays to access related data.
Common Mistakes
- Saying
Countstores the mark. It does not; it selects which mark to access. - Giving the type as
STRINGbecause it is used with names. The index is numeric, so it must beINTEGER. - Describing it only as a counter without linking it to array access.
Things to Be Careful About
- Use the term index or subscript, which is the precise array vocabulary.
- Keep purpose and data type separate because the question asks for both.
- Do not confuse the array element, such as
Mark[Count], with the index variable itself.
The pseudocode statements in the following table may contain errors.
State the error in each case or write ‘NO ERROR’ if the statement contains no error.
Assume that any variables used are of the correct type for the given function.
| Statement | Error |
|---|---|
IF EMPTY ← "" THEN | |
Status ← IS_NUM(-23.4) | |
X ← STR_TO_NUM("37") + 5 | |
Y ← STR_TO_NUM("37" + "5") |
Answer
| Statement | Error |
|---|---|
IF EMPTY ← "" THEN | Use = for comparison, not ←. |
Status ← IS_NUM(-23.4) | IS_NUM should be given a string, so -23.4 should be in quotes. |
X ← STR_TO_NUM("37") + 5 | NO ERROR |
Y ← STR_TO_NUM("37" + "5") | + is incorrect for combining strings before conversion. |
See completed table
Background Concept
When checking pseudocode statements, you need to know three common areas where errors occur:
-
Assignment vs comparison
←assigns a value to a variable.=compares two values.
In a condition such asIF ... THEN, you normally need a comparison, not an assignment.
-
Function argument types
Some functions expect a particular type of input. For example,STR_TO_NUMexpects a string representation of a number, andIS_NUMis used to test whether a string can be interpreted as numeric. -
Operator rules
An expression must use operators in a way allowed by the pseudocode style being used. If an operator is being applied to the wrong type of data, that is an error.
Understanding the Question
You are given four pseudocode statements. For each one, you must decide whether it is valid as written. If it is valid, write NO ERROR. If it is not valid, identify the mistake.
The question even says to assume variables are of the correct type for the given function, so the focus is on whether the statement itself uses the operator or function correctly.
Approach
Check each statement in order:
- Is a comparison being written correctly?
- Is the function being given the right kind of argument?
- Is the result being used in a valid expression?
- Are strings and numbers being handled in the correct order?
Step-by-Step Reasoning
1. IF EMPTY ← "" THEN
This is an IF condition, so it must test whether two values are equal.
← means assign, not compare. That makes this invalid. The statement should use =.
So the error is: using ← instead of =.
2. Status ← IS_NUM(-23.4)
IS_NUM is used to check whether a string contains a valid numeric value. Here, -23.4 has been written as a numeric literal rather than a string.
So the issue is the argument type. It should be a string such as "-23.4".
So the error is: IS_NUM should be given a string, not a numeric literal.
3. X ← STR_TO_NUM("37") + 5
STR_TO_NUM("37") converts the string "37" into the number 37. After that, adding 5 is valid.
So this statement is correct.
Answer: NO ERROR.
4. Y ← STR_TO_NUM("37" + "5")
This attempts to combine two strings using + before converting them to a number. In this pseudocode context, that is treated as incorrect string handling.
So the error is the use of + to combine the strings before conversion.
Key Takeaways
- Use
=in conditions and←for assignment. - Check that built-in functions are given the correct type of argument.
- Convert strings to numbers before doing arithmetic with them.
- Read each statement carefully; some are valid exactly as written.
Common Mistakes
- Writing
←in anIFstatement. That is assignment, not comparison. - Assuming a function like
IS_NUMaccepts any value just because the result is Boolean. - Marking
STR_TO_NUM("37") + 5as wrong because it mixes string and number. It does not: the conversion happens first. - Missing the order of evaluation in the final statement.
Things to Be Careful About
- The exact operator matters.
=and←are not interchangeable. - Watch whether something is a string literal or a numeric literal. Quotes make the difference.
- When a question says write
NO ERRORif correct, do not invent a problem that is not there. - Use the function names and operator rules from the insert exactly as defined for this exam.
The rest of this paper
7 more questions- Q2Algorithm Design and Problem-solving5M
- Q3Data Types and Structures · Algorithm Design and Problem-solving5M
- Q4Data Types and Structures12M
- Q5Data Types and Structures · Programming5M
- Q6Algorithm Design and Problem-solving · Programming7M
- Q7Algorithm Design and Problem-solving · Programming · Software Development10M
- Q8Data Types and Structures · Programming · Software Development19M