computer science 2015 upper 6 main paper 2

Upload: hbass

Post on 03-Mar-2016

216 views

Category:

Documents


0 download

DESCRIPTION

Computer Science Paper 2

TRANSCRIPT

Adventist College Phoenix2nd Term Exams 2015Upper 6Computer SciencePaper 2

Time: 2hrs

Name: _____________________

Class: ________________

Examiner: __________________

Throughout the paper you will be asked to write either pseudocode or program code.

Complete the statement to say which high-level programming language you will use.

Programming language used: ............................................

Question 1A program is to be written to enter and display the first five riders on a mountain top in a stage of a multiple stage of the Tour De France bike racing competition.

The first rider gets a 30 points bonus.

The second rider gets a 15 points bonus.

The third rider gets a 10 points bonus.

The fourth rider gets a 5 points bonus.

The fifth rider gets a 3 points bonus.The structured English description of the problem is shown here:

01 Input surname of each rider

02 Input other names of each rider

03 Input position of each rider

04 Input team of player

05 Calculate the bonus points for each rider

06 Store the points in a provisionary table (which will later be added to the

mountains classification table)

07 Repeat step 01 until all 5 riders have been input

Typical output is shown:RankRider NameOther NamesTeamPoints

1FroomeChristopherSky30

2PantaniMarcoCarrera15

3ContadorAlbertoGarmin10

4VirenqueRichardFDJ5

5JalabertLaurentOnce3

i. Study the structured english and complete the identifiers table below:

IdentifierData typeDescription

RiderSurnameStringSurname of the rider

[5]

ii. Explain why the identifier RiderSurname is written in this way__________________________________________________________________

_______________________________________________________________[1]iii. Suggest another acceptable way you could have written the identifier __________________________________________________________________

_______________________________________________________________[1]b) A record should be used to store details for riders. Write a piece of code in a programming language for the declaring the record structure.

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________

_______________________________________________________________ [5]c) Write program code from this structured English (in page 2)

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________[9]d) Line 05 in the structured English does not give sufficient details to write program code from this statement.

Use Stepwise refinement to give detail for line 05.

[5]

Question 2The rider with the lowest aggregate time is the leader of the race and is on top of general classification table. At the end of each stage, the time for that stage is added to the table. The table needs to be sorted again

a) Complete the pseudocode below that uses bubble sort to procedure bubbleSort( A as Array ) do ___________ = false for each i in 1 to length(A) - 1 inclusive do: if A[i-1].aggregatetime > __________________ then swap( _____________, A[i] ) swapped = ______________ end if end for while swappedend ________________[5]b) Give two benefits of using procedures.

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________

_______________________________________________________________ [2]

Question 3The record needs to be stored in a file.

a) Explain why we need to store data in a file.

_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________[1]

(b) Write program code that will store the record of 200 riders in a file call riders.dat.

________________________________________________________________________________________________________________________________________________________________________________________________________________________

________________________________________________________________________________________________________________________________________________________________________________________________________________________

________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

________________________________________________________________________________________________________________________________________________________________________________________________________________________

________________________________________________________________________________________________________________________________________________________________________________________________________________________

_____________________________________________________________________________________________________________________________________________________________________________________________________________________[9]Question 4There are different types of riders. The trainer may use the Body Mass Index (BMI) to determine what category suits mosts to a rider

Among the categories there are

Climbing specialist

puncheur

Sprinter

The formula below is used to get the BMI of a rider

FUNCTION GetBMI ( mass: Integer, height: Real) RETURNS real

1 2 3 4

a) Explain the various parts of the Function header.

1. __________________________________________________________________

__________________________________________________________________

2. __________________________________________________________________ __________________________________________________________________

3. __________________________________________________________________

__________________________________________________________________

4. __________________________________________________________________ ________________________________________________________________[4]b) This statement is used in pseudocode

GetBMI (80, 1.8)

What value will it return?

_____________________________________________________________[2]Question 5

A student is experimenting with String manipulation. He testes the following functions in a program.

Substr

OnecharCharactercountConcat

CHRASC

The figure below show part of the standard ASCII character codes:

a) He uses the following string variable in his program.

MyString Paper 2 is a difficult paper

Using the substr function, write expressions to return

i. paper

_______________________________________________________________[1]

ii. difficult

_______________________________________________________________[1]

iii. Complete the pseudocode that will return the following:

P

Pa

Pap

Pape

Paper

For count ____ to ____

print ( substr ( _______, _____, _____ ))

next

[5]

b) Use the ascii code table to find the value of

ASC(F) + ASC(P)

_______________________________________________________________[1]

ASC(O) - ASC(K)

_______________________________________________________________[1]

c) Give the string produced by the following expressions

i. CHR(81) & CHR(85) & CHR(69) & CHR(69) & CHR(78)

_______________________________________________________________[1]

ii. SUBSTR(CHR(66) & CHR(69) & CHR(65) & CHR(84), 2, 4)

_______________________________________________________________[2]

iii. concat (Big, , Ben)

_______________________________________________________________[1]

iv. concat(concat(Mall, of), Mauritius)

_______________________________________________________________[2]

v. concat (CHR(81), , ASC(A))

_______________________________________________________________[2]

vi. CHARACTERCOUNT (Adventist College) + 5

_______________________________________________________________[1]

vii. ONECHAR(Camel, 1) & ONECHAR(Nuts, 2) & ONECHAR(sa, 1) & ONECHAR(Ki, 2) & ONECHAR(BON, 3) & ONECHAR(sa, 1)

____________________________________________________________[2]

Quesition 6

The students is now experimenting with maths expression. Besides the normal +, -, * and / expressions he also works with the following:

The expression 17 DIV 7 evaluates to 2

The expression 17 MOD 3 evaluates to 3

The expression ROUND(4.6) evaluates to 5

The expression ROUND(4.2) evaluates to 4

The expression FLOOR(4.6) evaluates to 4

The expression CEILING(4.6) evaluates to 5

Write expressions to find the

a) The sum of 5 and 10

_______________________________________________________________[1]

b) the remainder when 13 is divided by 3

_______________________________________________________________[1]

c) the integreal part of 10.5

_______________________________________________________________[1]

d) 10.8 rounded to the nearest integer

_______________________________________________________________[1]

e) the quotient when 13 is divided by 3

_______________________________________________________________[1]

f) the nearest intgeger greater than 10.2

_______________________________________________________________[1]

Page 13 of 13