Algorithm design and problem-solving – A Level Computer Science (9618)
35 questions · page 2 of 3 · Clear filters
Question text
2
A program is being developed.
(a) An algorithm for part of the program will:
•
input three numeric values and assign them to identifiers Num1, Num2 and Num3
•
assign the largest value to variable Ans
•
output a message giving the largest value and the average of the three numeric values.
Assume the values are all different and are input in no particular order.
Complete the program flowchart on page 5 to represent the algorithm.
START
INPUT Numl, Num2, Num3
No
Yes
END
[5]
(b) A different part of the program contains an algorithm represented by the following program
flowchart:
START
Set Flag to GetStat()
Yes
Is Flag =
TRUE ?
END
No
Set Port to 1
No
Is Port = 4 ?
CALL Reset(Port)
Yes
Set Port to Port + 1
Write pseudocode for the algorithm.
…
…
…
…
…
…
…
…
…
…
…
… [5]
Question text
1
A program uses many complex algorithms.
One algorithm is repeated in several places. The code for the algorithm is the same wherever it is
used, but the calculations within the algorithm may operate on different data.
The result of each calculation is used by the code that follows it.
It is decided to modify the program and implement the algorithm as a separate module.
(a) (i)
State two benefits of this modification to the existing program.
1 …
…
2 …
…
[2]
(ii)
Describe how the modification would be implemented.
…
…
…
…
…
…
…
… [3]
,
,
(b) Four of the expressions used in the program are represented by pseudocode in the table.
Complete each pseudocode expression with a function or operator so that it evaluates to the
value shown.
Any functions and operators used must be defined in the insert.
Pseudocode expression
Evaluates to
"and"
… ("Random", 2, 3)
15
5 + … (10/11/2023)
TRUE
… ("45000")
3
(20 … 3) + 1
[4]
Question text
2
(a) An algorithm is expressed as follows:
•
input 100 numbers, one at a time
•
keep a total of all numbers input that have a value between 30 and 70 inclusive and
output this total after the last number has been input.
Outline, using stepwise refinement, the five steps for this algorithm which could be used to
produce pseudocode.
Do not use pseudocode statements in your answer.
Step 1 …
…
Step 2 …
…
Step 3 …
…
Step 4 …
…
Step 5 …
…
[5]
(b) Sequence is one programming construct.
Identify two other programming constructs that will be required when the algorithm is
converted into pseudocode.
Construct 1 …
…
Construct 2 …
…
[2]
Question text
1
A shop sells car accessories. A customer order is created if an item cannot be supplied from
current stock. A program is being developed to create and manage the customer orders.
(a) The following identifier table shows some of the data that will be stored for each order.
Complete the identifier table by adding meaningful variable names and appropriate data
types.
Example
Explanation
Variable name
Data type
value
"Mr Khan"
The name of the customer
3
The number of items in the order
TRUE
To indicate whether this is a new customer
15.75
The deposit paid by the customer
[4]
(b) Other variables in the program have example values as shown:
Variable
Example value
Total
124.00
DepRate
2.00
Description
"AB12345:Cleaning Brush (small)"
Complete the table by evaluating each expression using the example values.
Expression
Evaluates to
(Total * DepRate) + 1.5
RIGHT(Description, 7)
(LENGTH(Description) - 8) > 16
NUM_TO_STR(INT(DepRate * 10)) & '%'
[4]
(c) The data that needs to be stored for each customer order in part (a) is not all of the same
type.
Describe an effective way of storing this data for many customer orders while the program is
running.
…
…
…
…
…
… [3]
Question text
2
An algorithm will:
1.
input a sequence of integer values, one at a time
2.
ignore all values until the value 27 is input, then sum the remaining values in the sequence
3.
stop summing values when the value 0 is input and then output the sum of the values.
(a) Draw a program flowchart to represent the algorithm.
START
END
[5]
(b) The solution to the algorithm includes iteration.
Give the name of a suitable loop structure that could be used.
Justify your answer.
Name …
Justification …
…
[2]
Question text
5
A global 1D array of integers contains four elements, which are assigned values as shown:
← 1
Mix[1]
← 3
Mix[2]
← 4
Mix[3]
← 2
Mix[4]
A procedure Process() manipulates the values in the array.
The procedure is written in pseudocode:
PROCEDURE Process(Start : INTEGER)
DECLARE Value, Index, Count : INTEGER
← Start
Index
← 0
Count
REPEAT
←
Mix[Index]
Value
←
Mix[Index] - 1
Mix[Index]
←
Value
Index
←
Count + 1
Count
UNTIL Count = 5
← Count * Index
Mix[4]
ENDPROCEDURE
Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:
CALL Process(3)
Index
Value
Count
Mix[1]
Mix[2]
Mix[3]
Mix[4]
[6]
Question text
5
A global 1D array of integers contains four elements, which are assigned values as shown:
← 4
Mix[1]
← 2
Mix[2]
← 3
Mix[3]
← 5
Mix[4]
A procedure Process() manipulates the values in the array.
The procedure is written in pseudocode as follows:
PROCEDURE Process(Start : INTEGER)
DECLARE Value, Index, Total : INTEGER
← Start
Index
← 0
Total
WHILE Total < 20
←
Mix[Index]
Value
←
Total + Value
Total
IF Index < 4 THEN
←
Mix[Index] + Mix[Index+1]
Mix[Index]
ELSE
←
Mix[Index] + Mix[1]
Mix[Index]
ENDIF
←
(Value MOD 4) + 1
Index
ENDWHILE
← Total * Index
Mix[1]
ENDPROCEDURE
Complete the trace table on the opposite page by dry running the procedure when it is called as
follows:
CALL Process(2)
Index
Value
Total
Mix[1]
Mix[2]
Mix[3]
Mix[4]
[6]
Question text
2
A program contains an algorithm to output a string of a specified length containing identical
characters.
(a) The algorithm is described as follows:
1.
prompt and input a character and store in MyChar
2.
prompt and input an integer and store in MyCount
3.
generate a string consisting of MyChar repeated MyCount times
4.
output the string.
Draw a program flowchart to represent the algorithm.
START
END
[4]
(b) A different part of the program uses the variable StartDate.
Write pseudocode statements to declare StartDate and assign to it the date corresponding
to 15/11/2005.
Declaration …
Assignment …
[3]
Question text
3
Customers collect points every time they make a purchase at a store.
A program is used to manage the points system and the table lists some of the information stored
for one customer.
Information
Data type required
Name
String
Number of points collected
Integer
Date of birth
Date
(a) (i)
Identify a suitable structure for storing the information for one customer. Explain the
advantage of using this structure.
Structure …
Advantage …
…
…
…
…
…
[4]
(ii)
Describe a data structure that could be used to store the information for all customers.
…
… [2]
(b) Customers receive points depending on the amount they spend. The number of points
depends on the band that the amount falls into:
Band
Amount
Points
1
Less than $10
5 per whole dollar ($)
2
Between $10 and $100 inclusive
7 per whole dollar ($)
3
Over $100
10 per whole dollar ($)
For example, if the amount is $99.77, this amount is in band 2 and therefore the number of
points is 7 × 99, which is 693 points.
The algorithm to calculate the points from a given amount is expressed as follows:
•
work out the appropriate band
•
calculate and output the number of points.
Apply the process of stepwise refinement to increase the detail of the algorithm. Structure
your algorithm into a sequence of five steps that could be used to produce pseudocode.
Write the five steps.
1 …
…
…
2 …
…
…
3 …
…
…
4 …
Question text
2
A system is being developed to help manage a car hire business. A customer may hire a car for a
number of days.
An abstract model needs to be produced.
(a) Explain the process of abstraction and state four items of data that should be stored each
time a car is hired.
Explanation …
…
Item 1 …
Item 2 …
Item 3 …
Item 4 …
[3]
(b) Identify two operations that would be required to process the car hire data.
Operation 1 …
…
Operation 2 …
…
[2]
Question text
4
The program flowchart represents a simple algorithm.
START
INPUT UserID
Set Average to
GetAverage(UserID)
Set Total to 0
Set Index to 4
Add 1 to Index
YES
Is Index < 7 ?
NO
Set Last to
SameMonth[Index]
NO
Is Average
Add Last to Total
> Last ?
YES
Add Average to Total
Update(UserID, Total)
END
(a) Write the equivalent pseudocode for the algorithm represented by the flowchart.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) Give the name of the iterative construct in the flowchart.
… [1]
Question text
3
An algorithm is needed to process a sequence of numbers. Numbers may be positive or negative
and may be integer or decimal.
The algorithm will:
•
prompt and input one number at a time until the value zero is input
•
sum the negative numbers
•
sum the positive numbers
•
when zero is input, output the two sum values and then end.
Describe the algorithm needed. Do not include pseudocode statements in your answer.
…
…
…
…
…
…
…
…
…
…
…
… [5]
Question text
5
Each line of a text file contains data organised into fixed-length fields as shown:
<Field 1><Field 2><Field 3>
An algorithm is required to search for the first instance of a given value of Field 2 and, if found, to
output the corresponding values for Field 1 and Field 3.
Describe the algorithm needed.
Do not include pseudocode statements in your answer.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
Question text
6
(a) An algorithm will:
•
output each integer value between 100 and 200 that ends with the digit 7, for example,
107
•
output a final count of the number of values that are output.
Write pseudocode for this algorithm.
Any variables used must be declared.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) Study the following pseudocode.
CASE OF MySwitch
'a'
1: ThisChar
'y'
2: ThisChar
'7'
3: ThisChar
'*'
OTHERWISE: ThisChar
ENDCASE
Write pseudocode with the same functionality without using a CASE structure.
…
…
…
…
…
…
…
…
…
Question text
1
(a) A programmer is testing a program using an Integrated Development Environment (IDE).
The programmer wants the program to stop when it reaches a specific instruction or program
statement in order to check the value assigned to a variable.
Give the technical term for the position at which the program stops.
… [1]
(b) The following table lists some activities from the program development life cycle.
Complete the table by writing the life cycle stage for each activity.
Activity
Life cycle stage
An identifier table is produced.
Syntax errors can occur.
The developer discusses the program requirements with the customer.
A trace table is produced.
[4]
(c) An identifier table includes the names of identifiers used.
State two other pieces of information that the identifier table should contain.
1 …
2 …
[2]
(d) 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.
You can assume that none of the variables referenced are of an incorrect type.
Statement
Error
TRUE AND FALSE
Status
IF LENGTH("Password") < "10" THEN
Code
LCASE("Electrical")
Result
IS_NUM(-27.3)
[4]