Databases and SQL – IGCSE Computer Science (0478)
Question text
2
This section of program code asks for 50 numbers to be entered. The total and average of the
numbers are calculated.
1
Total = 0
2
Counter = 50
3
PRINT ′When prompted, enter 50 numbers, one at a time′
4
REPEAT
5
PRINT ′Enter a number′
6
INPUT Number
7
Total + Number = Total
8
Number = Number + 1
9
UNTIL Counter = 50
10
Average = Number * Counter
11
PRINT ′The average of the numbers you entered is ′, Average
There are four errors in this code.
State the line number for each error and write the correct code for that line.
Error 1 Line number …
Correct code …
Error 2 Line number …
Correct code …
Error 3 Line number …
Correct code …
Error 4 Line number …
Correct code …
[4]
Question text
7
A television (TV) store has a database table, TVSTOCK, for its new range of televisions. The table
stores the screen size of each TV, whether it will show 3D, whether the screen is curved or flat,
if the internet is available on the TV, if it has a built-in hard disk drive and the price. Part of the
database table is shown below.
TVID
ScreenSize
3D
CurvedFlat
Internet
HDD
Price
TV80CVINT
80
YES
CV
YES
YES
$7,000.00
TV65CVINT
65
YES
CV
YES
YES
$5,000.00
TV60CVINT
60
YES
CV
YES
YES
$4,500.00
TV60FTINT
60
YES
FT
YES
YES
$4,000.00
TV55CVINT
55
YES
CV
YES
NO
$3,000.00
TV55FTINT
55
YES
FT
YES
NO
$3,500.00
TV55FTNIN
55
YES
FT
NO
NO
$3,000.00
TV50CVINT
50
YES
CV
YES
NO
$2,500.00
TV50FTINT
50
YES
FT
YES
NO
$2,000.00
TV50FTNIN
50
YES
FT
NO
NO
$1,750.00
TV42FTINT
42
YES
FT
YES
NO
$1,500.00
TV37FTINT
37
NO
FT
YES
NO
$1,200.00
TV20FTNIN
20
NO
FT
NO
NO
$800.00
TV15FTNIN
15
NO
FT
NO
NO
$400.00
(a) State the type of the field TVID and give a reason for your choice.
…
…
… [1]
(b) Complete the table with the most appropriate data type for each field.
Field name
Data type
ScreenSize
3D
CurvedFlat
Internet
HDD
Price
[3]
(c) Use the query-by-example grid below to provide a list of all of the curved screen TVs that
have a built-in hard disk drive. Make sure the list only displays the TVID, the price and the
screen size in ascending order of price.
Field:
Table:
Sort:
Show:
Criteria:
or:
[5]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
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 International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
4
An algorithm has been written in pseudocode to input 100 numbers and print out the sum.
A REPEAT … UNTIL loop has been used.
Count ← 0
Sum ← 0
REPEAT
INPUT Number
Sum ← Sum + Number
Count ← Count + 1
UNTIL Count > 100
PRINT Sum
(a) Find the error in the pseudocode and suggest a correction.
Error …
Correction …
…
[2]
(b) Rewrite the correct algorithm using a more suitable loop structure.
…
…
…
…
…
…
… [3]
Question text
5
A database table, SHEEP, is used to keep a record of the sheep on a farm. Each sheep has a
unique ear tag, EARnnnn; n is a single digit. The farmer keeps a record of the date of birth, the
gender and the current weight of each sheep in kilograms.
(a) Identify the four fields required for the database. Give each field a suitable name and data
type. Provide a sample of data that you could expect to see in the field.
Field 1 name …
Data type …
Data sample …
Field 2 name …
Data type …
Data sample …
Field 3 name …
Data type …
Data sample …
Field 4 name …
Data type …
Data sample …
[8]
(b) State the field that you would choose as the primary key.
… [1]
(c) Using the query-by-example grid below, write a query to identify the ear tags of all male
sheep weighing over 10 kilograms. Only display the ear tags.
Field:
Table:
Sort:
Show:
Criteria:
or:
[3]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
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 International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
5
(a) Rewrite the following pseudocode algorithm using a WHILE … DO … ENDWHILE loop.
INPUT Num
FOR Counter ← 1 TO 12
Num ← Num * Counter
A[Counter] ← Num
NEXT
…
…
…
…
…
…
…
…
…
… [4]
(b) Explain the differences between a WHILE … DO … ENDWHILE and a REPEAT … UNTIL
loop.
…
…
…
…
…
…
…
… [4]
Question text
6
A database table, DEVICE, has been set up to record the electronic equipment used in a small
business.
Device ID
Device Type
User
Purchase
Purchase
Portable
Date
Price ($)
3
Desktop
Alan Swales
14/02/2017
1350.00
N
4
Laptop
Chantel Law
01/02/2016
1460.00
Y
5
Tablet
Abdula Saud
31/12/2016
1000.00
Y
6
Desktop
Abdula Saud
14/03/2017
1000.00
N
7
Laptop
Alan Swales
15/03/2016
1700.00
Y
8
Tablet
Taona Jaji
16/12/2016
470.00
Y
(a) The query-by-example grid below selects certain records.
Field:
User
Portable
Purchase Price ($)
Table:
DEVICE
DEVICE
DEVICE
Sort:
Ascending
Show:
3
Criteria:
Y
>1000
or:
Show what would be the output from the query-by-example.
…
…
… [2]
(b) Complete the query-by-example grid below to select all Desktop devices that were either
purchased before 31/12/2016 or cost under $1000. Only show the Device ID and Device
Type.
Field:
Table:
Sort:
Show:
Criteria:
or:
[4]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
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 International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
2
Read this section of program code that:
•
inputs 10 numbers
•
checks whether each number is within a specified range
•
totals the numbers within the range and outside the range
1
InRange = 0
2
OutRange = 1000
3
FOR Count = 1 TO 10
4
INPUT Num
5
IF Num > 10 AND Num < 20 THEN InRange = InRange + 1
6
ELSE OutRange = OutRange - 1
7
Count = Count + 1
8
NEXT X
9
PRINT InRange, OutRange
(a) There are four errors in this code.
Locate these errors and suggest a correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
… [4]
(b) Decide, with reasons, whether the numbers 10 and 20 are within or outside the range.
Within
Outside
Number
Reason
range (✓)
range (✓)
10
… ..
… ..
20
… ..
… ..
[4]
Question text
6
A database, THEATRETOURS, was set up to show the tour dates, towns, number of seats and
prices in local currency for a Shakespeare play.
Town
Tour Date
Number of Seats
Price Local Currency
Wigan
18/08/2016
120
15.00
Dumfries
20/08/2016
160
12.50
Turin
25/08/2016
200
17.00
Macon
27/08/2016
75
18.00
Bordeaux
29/08/2016
170
20.00
Algiers
01/09/2016
125
1350.00
Windhoek
05/09/2016
65
90.00
Windhoek
06/09/2016
65
90.00
Port Elizabeth
10/09/2016
200
110.00
(a) Explain why none of the fields in the database can be used as a primary key.
…
…
… [2]
(b) State a field that could be added as a primary key.
…
Give a reason for choosing this field.
…
… [2]
(c) Use the query-by-example grid below to provide a list of tour dates and seat prices in
alphabetical order of town.
Field:
Table:
Sort:
Show:
Criteria:
or:
[4]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
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 International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
2
Read this section of program code that inputs positive numbers, discards any negative numbers
and then outputs the average. An input of zero ends the process.
1
Total = 0
2
Counter = 100
3
REPEAT
4
REPEAT
5
INPUT Num
6
UNTIL Num < 0
7
Total = Total + 1
8
Counter = Counter + Num
9
UNTIL Num = 0
10
Average = Total / (Counter - 1)
11
Print Average
There are four errors in this code.
Locate these errors and suggest a correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
… [8]
Question text
5
A database, PLAYPRODUCTION, was set up to show the performance dates, prices and number
of seats available at a theatre specialising in Shakespeare productions.
Number
Number
Performance
Price Stalls
Price Circle
Play
Seats
Seats
Date
Seats $
Seats $
Stalls
Circle
As You Like It
01/07/2016
120
90
20.00
30.00
As You Like It
02/07/2016
85
45
30.00
40.00
As You Like It
09/07/2016
31
4
30.00
40.00
Macbeth
14/07/2016
101
56
25.00
35.00
Macbeth
15/07/2016
50
34
25.00
35.00
Macbeth
16/07/2016
12
5
35.00
50.00
Julius Caesar
22/07/2016
67
111
20.00
20.00
Julius Caesar
23/07/2016
21
24
15.00
15.00
A Comedy of Errors
30/07/2016
45
36
35.00
45.00
(a) Give the number of fields that are in each record.
… [1]
(b) State the data type you would choose for each of the following fields.
Play …
Number Seats Stalls …
Price Stalls Seats $ … [3]
(c) The query-by-example grid below selects all the productions with more than 100 seats left in
either the stalls or the circle.
Field: Play
Performance Date
Number Seats Stalls
Number Seats Circle
Table: PLAYPRODUCTION
PLAYPRODUCTION
PLAYPRODUCTION
PLAYPRODUCTION
Sort: Ascending
Show:
Criteria:
> 100
or:
> 100
Show what would be output from the query-by-example.
…
…
… [3]
(d) Complete the query-by-example grid below to select all the productions with at least six seats
left in the circle and show the Play, Performance Date and Price Circle Seats $ in Performance
Date order.
Field:
Table:
Sort:
Show:
Criteria:
or:
[5]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
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 International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
2
Read this section of program code that inputs 10 positive numbers and then outputs the smallest
number input.
1
Small = 1000
2
Counter = 0
3
REPEAT
4
INPUT Num
5
IF Num < Small THEN Small = Num
6
Counter = Counter + 1
7
UNTIL Counter = 10
8
PRINT Small
(i)
Identify three changes you would need to make to find the largest number input instead
of the smallest number.
1 …
…
2 …
…
3 …
… [3]
(ii)
Rewrite the program code with your changes.
…
…
…
…
…
…
…
… [3]
Question text
3
A program will be written to store information about members of a swimming club.
The following membership details will be recorded:
•
Name
•
Gender
•
Status:
•
Senior
•
Junior
•
Fee
•
Team member (Yes or No)
(i)
Choose a suitable data type for each of the membership details to be recorded.
Membership details
Data type
Name
Gender
Status
Fee
Team member
[5]
(ii)
The swimming club has 50 members.
State the data structure that would be most suitable to use and give a reason for your
choice.
Data structure …
Reason …
… [2]
Question text
6
A database, STAFFPHONE, was set up to show the telephone extension numbers for members of
staff working in a department store.
Name
Department
Extension number
Jane Smith
Toys
129
Sue Wong
Books
124
David Chow
Toys
129
Amy Tang
Household
123
Joe Higgs
Books
124
Jane Smith
Shoes
125
Adel Abur
Shoes
125
Peter Patel
Toys
129
(a) Explain why none of the fields in the database can be used as a primary key.
…
…
… [2]
(b) State a field that could be added as a primary key.
…
Give a reason for choosing this field.
…
… [2]
(c) Use the query-by-example grid below to provide a list of all members of staff, in alphabetical
order, grouped by department.
Field:
Table:
Sort:
Show:
Criteria:
or:
[5]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
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 International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
2
Read this section of program code that inputs 10 positive numbers and then outputs the total.
1
Total = 0
2
Counter = 0
3
REPEAT
4
INPUT Num
5
Total = Total + Num
6
PRINT Total
7
Counter = Counter + 1
8
UNTIL Counter = 10
This code works, but it is inefficient.
(i)
Suggest three improvements that could be made.
1 …
…
2 …
…
3 …
… [3]
(ii) Rewrite the program code with your improvements.
…
…
…
…
…
…
…
…
…
… [3]
Question text
6
Identify two different selection statements that you can use when writing pseudocode.
1 …
…
2 …
… [2]
Question 7 begins on page 10.