0% found this document useful (0 votes)
27 views14 pages

Final Built in Questions Worksheet

Uploaded by

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

Final Built in Questions Worksheet

Uploaded by

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

AS- Built In Function Worksheet

Computer Science

Name:____________ Class/Section:___________ Date:________


1 (a) A program stores data about hospital patients.

Give a suitable identifier name for each of the data items.

Description of data item Suitable identifier name


The temperature of the patient
The temperature of the room
The patient identification number
The name of the nurse taking the measurement
[4]
(b) (i) Program variables have values as follows:

B
Variable Value
MyGreeting "Happy Birthday"
MyInitial 'C'
AgeInYears
Weight
27
60.5
AI
H
Married TRUE
Children TRUE
ZO

Evaluate each expression in the following table.


If an expression is invalid, write ERROR.
For the built-in functions list, refer to the Appendix on page 15.

Expression Evaluates to
"Mon" & MID(MyGreeting, 10, 2)
S

AgeInYears + ASC(MyInitial)
INT(MyInitial)
C

MOD(Weight * 2, 10)
Married AND (NOT Children)
[5]
(ii) Programming languages support different data types.

Give an appropriate data type for each of these variables from part (b)(i).

Variable Data type


MyGreeting
MyInitial
AgeInYears
Weight
Married
[5]
15

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

B
Example: LEFT("ABCDEFGH", 3) returns string "ABC"

LCASE(ThisChar : CHAR) RETURNS CHAR


AI
returns the character value representing the lower case equivalent of ThisChar

If ThisChar is not an upper-case alphabetic character then it is returned unchanged.


H
Example: LCASE('W') returns 'w'

INT(x : REAL) RETURNS INTEGER


ZO

returns the integer part of x

Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER


returns the ASCII value of character ThisChar
S

Example: ASC('A') returns 65


C

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

Operators (pseudocode)

Operator Description
Concatenates (joins) two strings
&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE produces FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE produces TRUE
2 (a) A program controls the heating system of an energy-efficient house.
Give a suitable identifier name for each of the data items.

Description of data item Suitable identifier name


The temperature inside the house
The temperature outside the house
The wind speed
Whether it was raining or not
[4]

(b) (i) Program variables have values as follows:

Variable Value
Quality 'D'

B
DayNumber 20
MyName "Stephen"
QualityConfirmed
Factor
AI
TRUE
6.5
H
Evaluate each expression in the following table.
ZO

If an expression is invalid, write ERROR.

For the built-in functions list, refer to the Appendix on page 15.

Expression Evaluates to
S

MID(MyName, 4, 4) & "ol"


QualityConfirmed AND (Factor >= 6.5)
C

20 + ASC(Quality)
QualityConfirmed + 3
MOD(Factor * 2, 9)
[5]
(ii) Programming languages support different data types.

Give an appropriate data type for each of these variables from part (b)(i).

Variable Data type


QualityConfirmed

DayNumber

Factor

Quality

MyName
[5]

B
AI
H
ZO
S
C
3

C
S
ZO
H
AI
B
C
S
ZO
H
AI
B
Q2.

C
S
ZO
H
AI
B
C
S
ZO
H
AI
B
Q.2
Q.1

C
S
ZO
H
AI
B
Q.3

Q4.
C
S
ZO
H
AI
B
Q6.
Q5.

C
S
ZO
H
AI
B
C
S
ZO
H
AI
B
18

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of string ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

B
Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

INT(x : REAL) RETURNS INTEGER


returns the integer part of x AI
H
Example: INT(27.5415) returns 27

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


ZO

returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString
S

Example: MID("ABCDEFGH", 2, 3) returns string "BCD"


C

LCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the lower case equivalent of ThisChar
If ThisChar is not an upper-case alphabetic character, it is returned unchanged.

Example: LCASE('W') returns 'w'

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the whole number part of the result when ThisNum is divided
by ThisDiv

Example: DIV(10,3) returns 3

NUM_TO_STRING(x : REAL) RETURNS STRING


returns a string representation of a numeric value.
Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

© UCLES 2020 9608/21/O/N/20


19

Operators (pseudocode)

Operator Description

Concatenates (joins) two strings


&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"

Performs a logical AND on two Boolean values


AND
Example: TRUE AND FALSE produces FALSE

Performs a logical OR on two Boolean values


OR
Example: TRUE OR FALSE produces TRUE

B
AI
H
ZO
S
C

© UCLES 2020 9608/21/O/N/20

You might also like