0% found this document useful (0 votes)
26 views17 pages

Question Paper 4

as level comp

Uploaded by

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

Question Paper 4

as level comp

Uploaded by

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

3

Refer to the insert for the list of pseudocode functions and operators.

1 A programmer has written a program which includes the function


Calculate(). When the program is run, the function returns an
unexpected value.

(a) The algorithm for function Calculate() contains the three pseudocode
statements shown.

Describe the error in each statement or write ‘no error’ if the statement contains

no error. Assume any variables used are of the correct type for the given function.

Statement 1: Index STR_TO_NUM(("27") + 2)

Error ..........................................................................................................................
................

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

Statement 2: Index STR_TO_NUM(MID("CPE1704TKS", 4, 2))

Error ..........................................................................................................................
................

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

Statement 3: IF MONTH(ThisDate) > '6' THEN

Error ..........................................................................................................................
................

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

[Turn over
2

(b) The program contains variables with values as follows:

Variable Value
Active TRUE
Points 75
Exempt FALSE

(i) Complete the table by evaluating each expression.

Expression Evaluation

1 (Points > 99) OR Active

2 (Points MOD 2 = 0) OR Exempt

3 (Points <= 75) AND (Active OR Exempt)

4 (Active OR NOT Active) AND NOT Exempt

[2]

(ii) Write expression 4 from the table in part (c)(i) in its simplest form.

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

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]
5

(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]

[Turn over
6

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 Integer
collected
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]
7

(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 7 per whole dollar ($)
inclusive
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 ................................................................................................................................
................
[Turn over
8

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

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

5 ................................................................................................................................
................

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

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

4 Function Replace() will:


1. take three parameters:
• a string (the original string)
• a char (the original character)
• a char (the new character)

2. form a new string from the original string where all instances of the original
character are replaced by the new character

3. return the new string.

Write pseudocode for function Replace().

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

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

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

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

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

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

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

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

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

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

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

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

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

.........................................................................................................................................
.................
[Turn over
10

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

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

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

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

5 A video-conferencing program supports up to six users. Speech from each user is


sampled and digitised (converted from analogue to digital). Digitised values are
stored in array Sample.

The array Sample consists of 6 rows by 128 columns and is of type integer. Each row
contains 128 digitised sound samples from one user.

The digitised sound samples from each user are to be processed to produce a single
value which will be stored in a 1D array Result of type integer. This process will be
implemented by procedure Mix().

A procedure Mix() will:


• calculate the average of each of the 6 sound samples in a column
• ignore sound sample values of 10 or less
• store the average value in the corresponding position in Result
• repeat for each column in array Sample

The diagram uses example values to illustrate the process:

1 2 3 ... 126 127 128


1 20 20 20 30 30 2
2 20 20 30 50 30 3
3 20 20 40 40 40 4
Sample: 4 20 20 50 40 50 20
5 20 3 5 6 60 4
6 20 4 2 4 70 30

Result: 20 20 35 40 46 25

[Turn over
12

Write pseudocode for procedure Mix().

Assume Sample and Result are global.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.........................................................................................................................................
13
.................

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

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

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

[Turn over
14

6 A school has a computerised library system that allows students to borrow books for
a fixed length of time. The system uses text files to store details of students, books
and loans.

A new module is to be written which will generate emails to each student who has
an overdue book.

(a) Decomposition will be used to break down the problem of designing the new
module into sub-problems.

Identify three program modules that could be used in the design and describe their
use.

Module 1
...................................................................................................................................

Use ...........................................................................................................................
................

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

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

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

Module 2
...................................................................................................................................

Use ...........................................................................................................................
................

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

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

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

Module 3
...................................................................................................................................

Use ...........................................................................................................................
................

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

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

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

[Turn over
16

BLANK PAGE
17

BLANK PAGE
18

BLANK PAGE

You might also like