Paper 2 Exam 6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Cambridge IGCSE™

* 9 0 6 0 9 6 0 7 7 2 *

COMPUTER SCIENCE 0478/23


Paper 2 Problem-solving and Programming May/June 2021
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 12 pages.

DC (KN/SG) 202761/2
© UCLES 2021 [Turn over
2

1 Draw a line to connect each Data Type to the most appropriate Description.

Data Type Description

Real Must be a whole number

String Must be one of two values

Integer May be any number

Boolean May contain any combination of characters


[3]

2 Identify a suitable validation check that could be used for each piece of normal test data and
describe how it would be used. Each validation check must be different.

Test data for entering an email address: id27@cambridgeuniversity.com

Validation check name .....................................................................................................................

Description of use ............................................................................................................................

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

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

Test data for entering a year: 2021

Validation check name .....................................................................................................................

Description of use ............................................................................................................................

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

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

Test data for entering a name: Ericson-Bower

Validation check name .....................................................................................................................

Description of use ............................................................................................................................

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

..........................................................................................................................................................
[6]

© UCLES 2021 0478/23/M/J/21


3

3 The pseudocode algorithm should allow a user to input the number of scores to be entered and
then enter the scores. The scores are totalled, the total is output and the option to enter another
set of scores is offered.

1 Count 0 ←
2 REPEAT
3 FullScore 20 ←
4 INPUT Number
5 FOR StoreLoop 1 TO Number ←
6 INPUT Score
7 FullScore FullScore ←
8 UNTIL StoreLoop = Number
9 OUTPUT "The full score is ", FullScore
10 OUTPUT "Another set of scores (Y or N)?"
11 OUTPUT Another
12 IF Another = "N"
13 THEN
14 Count 1 ←
15 ENDIF
16 UNTIL Count = 1

(a) Identify the four errors in the pseudocode and suggest a correction for each error.

Error 1 .......................................................................................................................................

Correction .................................................................................................................................

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

Error 2 .......................................................................................................................................

Correction .................................................................................................................................

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

Error 3 .......................................................................................................................................

Correction .................................................................................................................................

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

Error 4 .......................................................................................................................................

Correction .................................................................................................................................

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

© UCLES 2021 0478/23/M/J/21 [Turn over


4

(b) Show how you could change the algorithm to store the individual scores in the array
ScoreArray[], then find and print the average score once the scores have all been entered.

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

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

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

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

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

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

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

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

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

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

© UCLES 2021 0478/23/M/J/21


5

4 The flowchart represents an algorithm.

The algorithm will terminate if 0 is entered at the Op input.

START

INPUT
Op

IS No
Op = 0 ?

Yes
INPUT
Value1

INPUT
Value2

IS Yes
Op = 1 ? Ans Value1 + Value2

END No

IS Yes
Op = 2 ? Ans Value1 - Value2

No

IS Yes
Op = 3 ? Ans Value1 * Value2

No

IS Yes
Op = 4 ? Ans Value1 / Value2

No

OUTPUT
"Input Error"

© UCLES 2021 0478/23/M/J/21 [Turn over


6

(a) Complete the trace table for the algorithm using this input data:1,

87, 14, 3, 2, 30, 5, 10, 6, 4, 10, 2, 0, 2, 90, 6

Op Value1 Value2 Ans OUTPUT

[5]

(b) State the purpose of the algorithm.

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

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

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

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

(c) Suggest an addition that could be made to the algorithm to make it more useful.

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

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

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

© UCLES 2021 0478/23/M/J/21


7

5 A car hire company uses a database table, TREAD, to store details of the cars. The table has
fields to represent each car’s licence number, mileage, and the tread depth of each of its four
tyres.

(a) Suggest suitable names for each of the fields described.

Field name

[2]

(b) Give two validation checks that could be performed on the licence number field

Validation Check 1 ...........................................................................................................

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

Validation Check 2 ...........................................................................................................

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

[2]

(c) Complete the structured query language (SQL) to display cars where all four tyres have a tread
depth of less than 2. Display all the fields. The output should be sorted by licence number.

SELECT .................................................................................................................................

FROM .....................................................................................................................................

WHERE ....................................................................................................................................

ORDER BY .............................................................................................................................;

[4]

© UCLES 2021 0478/23/M/J/21 [Turn over


8

6 Consider the following logic circuit:

X
B

(a) Two NOT gates are used in the given logic circuit.

Identify three other logic gates that are used in the given logic circuit.

1 ................................................................................................................................................

2 ................................................................................................................................................

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

© UCLES 2021 0478/23/M/J/21


9

(b) Consider the completed truth table for the given logic circuit.

Row Working space


A B C X
number
1 0 0 0 0

2 0 0 1 1

3 0 1 0 0

4 0 1 1 0

5 1 0 0 1

6 1 0 1 1

7 1 1 0 0

8 1 1 1 1

There are four errors in the truth table in the output (X) column.

Identify the four incorrect outputs.

Write the row number to identify each incorrect output.

Row .......................

Row .......................

Row .......................

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

© UCLES 2021 0478/23/M/J/21 [Turn over


10

7 Four validation checks and four descriptions are shown below.


Draw a line to link each validation check to the correct description.

[4]

8 A function LENGTH(X) finds the length of a string X and a function SUBSTRING(X,Y,Z)


finds a substring of X starting at position Y and Z characters long. The first character in the
string is position 1.

Show the value of the variable after each pseudocode statement has been executed.

01 P ¬ "Library Routines" ........................................................................................

02 Q ¬ LENGTH(P) ............................................................................................................

03 R ¬ SUBSTRING(P,6,5) ............................................................................................

04 S ¬ LENGTH(R) ..............................................................................................................

05 T ¬ SUBSTRING(R,2,3) ............................................................................................

[5]

© UCLES 2021 0478/23/M/J/21


11
9 The function Min(A,B)takes 2 whole numbers and returns the smaller number.
Write pseudocode statements to:
• define the function
• call the function with 5, 8 and store the return value in Z

Function definition

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

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

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

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

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

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

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

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

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

Function call

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

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

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

.......................................................................................................................................................[6]

© UCLES 2021 0478/23/M/J/21 [Turn over


12
10 WHILE..DO..ENDWHILE and REPEAT..UNTIL are two different loop structures that you could
use when writing a pseudocode.

Explain using examples why you would choose to use each loop structure.

Example 1 .................................................................................................................................

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

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

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

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

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

Reason for choice ....................................................................................................................

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

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

Example 2 .................................................................................................................................

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

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

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

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

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

Reason for choice ....................................................................................................................

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

................................................................................................................................................[6]

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 the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.

© UCLES 2021 0478/23/M/J/21


Nested Loops & 2D Arrays Eng. Omar El Safty

118 A one-dimensional (1D) array Employees[] contains the names of employees in a law
firm. A two-dimensional array Salaries[] contains the monthly salary of each
employe in each month. The position of each employee data in the two arrays is the
same, for example, the employee in position 5 in Employees[] and Salaries[] is
the same.

The variable FirmSize contains the number of employees in the firm. The variable
Months contains the number of months of operation in the firm. All employees have
worked in the firm the same number of months.

The company allocates a monthly budget ranging from 50,000 EGP to 60,000 EGP.
Write a program that meets the following requirements:

• calculates the total salary paid by the law firm in each month
• find and output the number of months where the firm has gone over budget
• find and output the number of months where the firm has gone under budget
• find and output the number of months where the firm has been within budget
• find and display the average monthly wage paid by the firm to all employees

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

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

All inputs and outputs must contain suitable messages.You do not need to initialise the
data in the arrays Employees[] and Salaries[] or the variables FrimSize and
Months

The arrays and variables have already been set up and the data is stored.

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

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

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

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

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

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

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

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

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

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

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

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

187
Nested Loops & 2D Arrays Eng. Omar El Safty

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

......................................................................................................................................................15

188

You might also like