0% found this document useful (0 votes)
37 views9 pages

Problem Solving Test 1

This document describes a computer science problem solving test with 3 questions. Question 1 involves string handling functions and checking if a string is a palindrome. Question 2 involves converting a number guessing game flowchart to pseudocode. Question 3 involves analyzing sales data from two websites over 28 days stored in arrays.

Uploaded by

bilal.jamal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views9 pages

Problem Solving Test 1

This document describes a computer science problem solving test with 3 questions. Question 1 involves string handling functions and checking if a string is a palindrome. Question 2 involves converting a number guessing game flowchart to pseudocode. Question 3 involves analyzing sales data from two websites over 28 days stored in arrays.

Uploaded by

bilal.jamal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Cambridge International AS & A Level

COMPUTER SCIENCE 9618


2022
Problem Solving Test 1
50 Minutes
You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 41.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.

This document has 9 pages.


1 (a) A high-level programming language has built-in string handling functions defined as follows:

MID(ThisString : STRING, x : INTEGER, n : INTEGER) RETURNS STRING

returns a string value consisting of n characters from the string ThisString starting from
position x.

For example: MID("STOP", 3, 2) returns "OP"

If the function call is not properly formed an error is generated.

CONCAT(String1 : STRING, String2 : STRING) RETURNS STRING

returns a string value consisting of String1 followed by String2.

For example: CONCAT("HE", "LLO") returns "HELLO"

If the function call is not properly formed an error is generated.

LENGTH(ThisString : STRING) RETURNS INTEGER

returns the number of characters in string ThisString.

For example: LENGTH("Hello") returns 5

If the function call is not properly formed an error is generated.

String1 ← "RED"

String2 ← "F"

What will be returned from the following function calls?

(i) MID(String1, 3, 1)

.......................................................................................................................................[1]

(ii) MID(String1, 3, 2)

.......................................................................................................................................[1]

(iii) CONCAT(String2, String1)

.......................................................................................................................................[1]

AS Computer Science 2 Problem Solving


(b) Meena wants to write code to reverse a string stored in the variable Original. The result is
to be stored in the variable Reverse.

(i) Use all the functions described in part (a) to write the pseudocode required to reverse
the string.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[5]

(ii) A palindrome is a string that reads the same backwards as forwards.

Complete the Boolean expression to check whether the two strings, Original and
Reverse, are palindromes.

IF .....................................................................................................................................

THEN

OUTPUT "This is a palindrome"

ENDIF [1]

AS Computer Science 3 Problem Solving


2 Raza wants to write a number-guessing game. He has drawn a flowchart of an algorithm:

START

MyNumber 
RANDOM(100)

The algorithm uses


EndGame 
● the built-in function RANDOM(x) which
FALSE
returns a random integer in the range 1
to x.
● the variables
Initialise
NumberOfGuesses ○ EndGame
○ Guess
○ MyNumber
Output ○ NumberofGuesses
“Guess my number
Type 0 (zero) to end
game”

Input Guess

Is Guess = 0 No Increment
? NumberOfGuesses

Yes

Output Is Guess = No Is Guess > No


“You gave up after” MyNumber ? MyNumber ?
NumberOfGuesses
Yes Yes

Output Output Output


“Correct - you took” “Too high - “Too low -
NumberOfGuesses try again” try again”
“to guess my number”

EndGame  TRUE EndGame  TRUE

No Is EndGame
TRUE?

Yes

END

AS Computer Science 4 Problem Solving


Convert the flowchart to pseudocode.

[6]

AS Computer Science 5 Problem Solving


3 A company creates two new websites, Site X and Site Y, for selling bicycles.
Various programs are to be written to process the sales data.

These programs will use data about daily sales made from Site X (using variable SalesX) and
Site Y (using variable SalesY).

Data for the first 28 days is shown below.


SalesDate SalesX SalesY
1 03/06/2015 0 1
2 04/06/2015 1 2
3 05/06/2015 3 8
4 06/06/2015 0 0
5 07/06/2015 4 6
6 08/06/2015 4 4
7 09/06/2015 5 9
8 10/06/2015 11 9
9 11/06/2015 4 1

28 01/07/2015 14 8

(a) Name the data structure to be used in a program for SalesX.

...............................................................................................................................................[2]

(b) The programmer writes a program from the following pseudocode design.

x 0
FOR DayNumber 1 TO 7
IF SalesX[DayNumber] + SalesY[DayNumber] >= 10
THEN
x x + 1
OUTPUT SalesDate[DayNumber]
ENDIF
ENDFOR
OUTPUT x
Describe, in detail, what this algorithm does.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[3]

AS Computer Science 6 Problem Solving


4 The data input for a variable HandInDate needs validating. It will be entered as DDMMYYYY.
• DD must be less than 32 and greater than 0
• MM must be less than 13 and greater than 0
• YYYY must be greater than 2012 and less than 2015

Draw a flowchart that shows the logic to validate the hand-in date. [5]

AS Computer Science 7 Problem Solving


5(a) Juan wants to use an array, NumberOfCopies to store whole
numbers.

• declare the array of size 5000


• initialise the array to 0

[4]

(b) Juan has little programming experience, but has to write code for this program. He has
written the following pseudocode statements.
For each statement describe what is wrong and write a correct version.

(i) IF Index > 5000 OR < 0 THEN OUTPUT "Error"

Description

Correct statement

[2]

(ii) NumberOfCopies[Index] + 1 ← NumberOfCopies[Index]

Description

Correct statement

[2]

(iii) NumberOfCopies[Index] ← "three"

Description

Correct statement

[2]

AS Computer Science 8 Problem Solving


(C) Juan needs to design the code for a part of the program that determines where
resources are kept. If the resource has:

• an ID less than 1001 it will be kept in Cabinet 1


• an ID between 1001 and 3000 it will be kept in Cabinet 2
o even numbered IDs in Drawer 1
o odd numbered IDs in Drawer 2
• an ID between 3001 and 5000 it will be kept in Cabinet 3

Write pseudocode that processes the variable ResourceID and outputs where the
resource is kept. Use nested IF statements.

[6]

AS Computer Science 9 Problem Solving

You might also like