You are on page 1of 3

1. The following are data types (labelled A – E).

A Integer
B Boolean
C Real
D Character
E String

For each of the values in the table, write the label of the most suitable data type. Use a label only
once.

Label
Value
(A – E)

43.13

"Curry-Howard"

978

(Total 3 marks)

2. The following function calculates the second hand price of different models of car. The parameter
condition is an integer with a value between 1 and 4 where 1 is excellent and 4 is very bad.

FUNCTION CarPrice(model, condition, age)


cost ← 0

IF model = 'Daley' THEN


cost ← 6000
ELSE
IF model = 'Minty' THEN
cost ← 4000
ELSE
cost ← 2000
ENDIF
ENDIF

CASE condition OF
1: cost ← cost – 100
2: cost ← cost – 300
3: cost ← cost – 500
4: cost ← cost – 1000
ENDCASE

cost ← cost / age

RETURN cost
ENDFUNCTION

Page 1 of 3
(a) FUNCTION and ENDFUNCTION are keywords in CarPrice that indicate it is a function. Which
other keyword indicates that it is a function?

___________________________________________________________________

___________________________________________________________________
(1)

(b) Tick the most appropriate data type of the variable cost.

Data Type Tick one box

Boolean

Character

Real

String

(1)

(c) Complete the trace table below showing the changes in the variable cost when the
function CarPrice is called with the following arguments:

CarPrice('Tidy', 4, 2)

cost

(4)
(Total 6 marks)

Page 2 of 3
3. Which three of the following are common data types that most programming languages provide?

Tick three boxes

Boolean

Except

Length

Integer

While

Character

Maximum

(Total 3 marks)

4. The following is a function:

FUNCTION IsPrefix (name, value)


IF name[1] = value
RETURN true
ELSE
RETURN false
ENDIF
ENDFUNCTION

(a) Give the name of one parameter used by this function.

___________________________________________________________________
(1)

(b) State the data type of name.

___________________________________________________________________
(1)

(c) State the data type of the return value.

___________________________________________________________________
(1)
(Total 3 marks)

Page 3 of 3

You might also like