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

0478_s24_qp_21

Uploaded by

Palaash
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)
23 views

0478_s24_qp_21

Uploaded by

Palaash
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/ 16

Cambridge IGCSE™

* 6 3 7 7 6 2 5 9 4 8 *

COMPUTER SCIENCE 0478/21


Paper 2 Algorithms, Programming and Logic May/June 2024

1 hour 45 minutes

You must answer on the question paper.

No additional materials are needed.

INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen. You may use an HB pencil for any diagrams or graphs.
● 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.
● Calculators must not be used in this paper.

INFORMATION
● The total mark for this paper is 75.
● 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 16 pages. Any blank pages are indicated.

DC (PQ/CT) 329143/3
© UCLES 2024 [Turn over
2

1 Tick (ü) one box to complete this sentence.

A validation check to make sure that an email address contains an ‘@’ sign is a

A range check.

B visual check.

C presence check.

D format check.
[1]

2 Four descriptions of programming concepts and five programming concepts are shown.

(a) Draw one line to link each description to the most appropriate programming concept.

Not all programming concepts will be used.

Description Programming concept

function
a subroutine that may not return a value

procedure
a value that is declared and used within a
specific procedure
parameter
a value that a procedure expects you to
supply when it is called
global variable

a subroutine that will always return a value


local variable

[4]

(b) Write the pseudocode to use a procedure named Average that passes the values 25 and 50
to the procedure.
CALL Average(25,50)
...................................................................................................................................................

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

© UCLES 2024 0478/21/M/J/24


3

(c) Outline the role of procedures and functions in creating a program that is easier to maintain.
- make the program easier to debug
...................................................................................................................................................
- they can eliminate redundant or repeated code
...................................................................................................................................................
- divide the program into smaller or manageable sections
...................................................................................................................................................

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

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

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

3 State what is meant by the data types integer and real.


Give an example of each.
a positive or negative whole number
Integer ..............................................................................................................................................

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

Example ...........................................................................................................................................
3

a positive or negative whole number with a decimal part


Real ..................................................................................................................................................

..........................................................................................................................................................
3.1
Example ...........................................................................................................................................
[4]

© UCLES 2024 0478/21/M/J/24 [Turn over


4

4 This pseudocode algorithm is intended to allow, at random, between 1 and 20 values to be entered
and totalled. The total and average of the entered values are output at the end of the algorithm.

01 DECLARE Loop : STRING


02 DECLARE Limit : INTEGER
03 DECLARE Value : REAL
04 DECLARE Total : REAL
05 Total 0
06 Limit ROUND(RANDOM() * 19,0) + 1
07 IF Loop 1 TO Limit
08 OUTPUT "Enter a number"
09 INPUT Loop
10 Total Total * Value
11 NEXT Loop
12 OUTPUT "The total of the numbers entered is ", Total
13 OUTPUT "The average of the numbers entered is ", Total / Limit

(a) Identify the line numbers of four errors in the pseudocode and suggest corrections.
1
Error 1 line number ...................................................................................................................

Correction .................................................................................................................................
DECLARE Loop : INTEGER

...................................................................................................................................................
7
Error 2 line number ...................................................................................................................
FOR Loop <-- 1 TO Limit
Correction .................................................................................................................................

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

9
Error 3 line number ...................................................................................................................
INPUT Value
Correction .................................................................................................................................

...................................................................................................................................................
10
Error 4 line number ...................................................................................................................

Correction .................................................................................................................................
Total <-- Total + Value

...................................................................................................................................................
[4]

(b) Write the pseudocode statement that would output the average calculated in line 13 of the
algorithm rounded to one decimal place.
ROUND(Total / Limit,1)
...................................................................................................................................................

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

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

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

© UCLES 2024 0478/21/M/J/24


5

(c) Explain how you should alter the original corrected algorithm to make sure that all the
numbers entered are between 1 and 500 inclusive. If any numbers fall outside these limits, a
replacement value is requested and entered.

You do not need to re-write the algorithm.

...................................................................................................................................................
After line 09, insert a WHILE loop to check if entered value is between 1 and

...................................................................................................................................................
500. If the value is not in range, output an error message and use input

...................................................................................................................................................
statement to ask for a new input.

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

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

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

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

............................................................................................................................................. [4]

5 Write the pseudocode statements to perform this task:


• accept the input of a whole number from 1 to 4 inclusive
• use a CASE statement to:
○ output the number (1 to 4 inclusive) that was entered
○ output the word “ERROR” if a 1 to 4 inclusive number was not entered.
INPUT Number
..........................................................................................................................................................
CASE OF Number
..........................................................................................................................................................
1 : OUTPUT 1
..........................................................................................................................................................
2 : OUTPUT 2
..........................................................................................................................................................
3 : OUTPUT 3
..........................................................................................................................................................

..........................................................................................................................................................
4 : OUTPUT 4

..........................................................................................................................................................
OTHERWISE OUTPUT "ERROR"

..........................................................................................................................................................
ENDCASE

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

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

© UCLES 2024 0478/21/M/J/24 [Turn over


6

6 The flowchart represents an algorithm.

START

Result Limit DIV 2 + 1


INPUT
Limit
OUTPUT
Numbers[Result]
Count 1

INPUT
Numbers[Count]
STOP

Count Count + 1

No IS Count >
Limit?

IS Numbers[Count] > No
Yes
Numbers[Count + 1]?
Flag TRUE

Yes

Swap Numbers[Count]
IS Flag = No
TRUE?

Numbers[Count] Numbers[Count + 1]
Yes

Flag False Numbers[Count + 1] Swap


Count 1

Flag True

Yes IS Count > No


Limit – 1?

Count Count + 1

© UCLES 2024 0478/21/M/J/24


7

(a) Complete the trace table for the input data:

7, 47, 50, 52, 60, 80, 63, 70

Numbers

Limit Count [1] [2] [3] [4] [5] [6] [7] Flag Swap Result OUTPUT

7 1 47
2 50
3 52
4 60
5 80
6 63
7 70
8 TRUE
1 FALSE
2
3
4
5 80
63 80 TRUE
6 80
70 80 TRUE
7
1 FALSE
2
3
4
5
6
7

4 60
[7]
© UCLES 2024 0478/21/M/J/24 [Turn over
8

(b) Outline the processes involved in the algorithm shown in the flowchart on page 6.
- set of numbers inputted
...................................................................................................................................................

- sorted in increasing order


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

...................................................................................................................................................
- median value is found

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

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

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

7 (a) Outline why it is useful to store data in a file.


- easily re-accisible/recalled
...................................................................................................................................................
- can be transfered easily
...................................................................................................................................................
- permanently stored and data wont get lost
...................................................................................................................................................

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

(b) The function LENGTH(X) calculates the length of a string X

Write the pseudocode statements to:


• read the contents of the text file Quotation.txt into an appropriate string variable that
has been declared
• output the string in upper case and the length of the string.

...................................................................................................................................................
DECLARE info : STRING
...................................................................................................................................................
OPENFILE Quotation.txt FOR READ
...................................................................................................................................................
READFILE Quotation.txt, info
...................................................................................................................................................
OUTPUT UCASE(info), LENGTH(info)
...................................................................................................................................................
CLOSEFILE Quotation.txt
...................................................................................................................................................

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

............................................................................................................................................. [4]

© UCLES 2024 0478/21/M/J/24


9

8 Consider the logic expression:

Z = (R OR NOT T) XOR (NOT S AND T)

(a) Draw a logic circuit for this logic expression.

Each logic gate must have a maximum of two inputs.

Do not simplify this logic expression.

S Z

[5]

(b) Complete the truth table from the given logic expression.

Working space
R S T Z

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

[4]

© UCLES 2024 0478/21/M/J/24 [Turn over


10

9 A database table called SoftDrinks stores details of the soft drinks sold by a small shop.

Field Example data

Name Cola

Supplier Cambridge Beverages

Container Can

SizeCl 330

NumberInStock 30

ReorderLevel 15

Reordered Yes

(a) State whether any of the given fields would be suitable as a primary key and give a reason for
your answer.
none since none are unique
...................................................................................................................................................

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

(b) Complete the structured query language (SQL) statement to return the number of cans the
shop has in stock.
SUM
SELECT ....................................................... NumberInStock
(.......................................................)

FROM .......................................................
SoftDrinks

WHERE .......................................................
Container = .......................................................
'Can' ;
[5]

© UCLES 2024 0478/21/M/J/24


11

BLANK PAGE

© UCLES 2024 0478/21/M/J/24 [Turn over


12

10 The one-dimensional (1D) array Clubs[] is used to store the names of 12 cricket clubs in a local
sports league.

The two-dimensional (2D) array Statistics[] is used to store, for each cricket club, the number
of:
• matches won
• matches drawn
• matches lost.

The 1D array Points[] is used to store the total number of points each cricket club has been
awarded.

The position of any cricket club’s data is the same in all three arrays. For example, the data in
index 2 of Statistics[] and index 2 of Points[] belongs to the cricket club in index 2 of
Clubs[]

The variable Matches stores the number of matches played by each team. Each team plays the
same number of matches.

Points are awarded for:


• a win – 12 points
• a draw – 5 points
• a loss – 0 points.

Write a program that meets the following requirements:


• allows the number of matches played to be input and stored, with a maximum of 22 matches
• validates the number of matches played
• allows the names of the cricket clubs to be input and stored
• allows the number of matches won, drawn and lost to be input and stored for each team
• validates the number of matches won, drawn or lost against the number of matches played
• asks the user to re-enter the number of matches won, drawn or lost if the total does not match
the number of matches played
• calculates and stores the total number of points for each club
• finds the cricket club or clubs with the highest number of points
• outputs the name or names of the winning club or clubs, the number of wins and the total
number of points awarded.

You must use pseudocode or program code and add comments to explain how your code works.

You do not need to declare any arrays or variables; you may assume that this has already been
done.

All inputs and outputs must contain suitable messages.

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

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

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

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

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

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

© UCLES 2024 0478/21/M/J/24


13

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

..........................................................................................................................................................
© UCLES 2024 0478/21/M/J/24 [Turn over
14

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.................................................................................................................................................. [15]
© UCLES 2024 0478/21/M/J/24
15

BLANK PAGE

© UCLES 2024 0478/21/M/J/24


16

BLANK PAGE

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.

© UCLES 2024 0478/21/M/J/24

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