0% found this document useful (0 votes)
7 views

Computer Assignmnet AS 4

Uploaded by

sumanbasnet80123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Computer Assignmnet AS 4

Uploaded by

sumanbasnet80123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment

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

1 (a) A program is being developed to help manage the membership of a football club.

Complete the following identifier table.

Example
Explanation Variable name Data type
value

The preferred name of the member


"Wong"
joining the football club

A value to indicate whether an


FALSE existing member of the club lives at
the same address

When the member joined the football


19/02/1983
club

The number of points a member has


1345 earned. Members of the club earn
points for different activities.
[4]

(b) Each pseudocode statement in the following table may contain an error due to the incorrect
use of the function or operator.

Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error.

You can assume that none of the variables referenced are of an incorrect type.

Statement Error

Result 2 & 4

SubString MID("pseudocode", 4, 1)

IF x = 3 OR 4 THEN

Result Status AND INT(x/2)

Message "Done" + LENGTH(MyString)

[5]

© UCLES 2021 9618/23/M/J/21


6

2. A program will:

• input 50 unique integer values


• output the largest value
• output the average of the values excluding the largest value.

Draw a program flowchart to represent the algorithm.

Variable declarations are not required.

It is not necessary to check that each input value is unique.

[6]
© UCLES 2021 9618/23/M/J/21
10

3 Study the following pseudocode. Line numbers are for reference only.

10 FUNCTION Convert(Name : STRING) RETURNS STRING


11
12 DECLARE Flag: BOOLEAN
13 DECLARE Index : INTEGER
14 DECLARE ThisChar : CHAR
15 DECLARE NewName : STRING
16
17 CONSTANT SPACECHAR = ' '
18
19 Flag TRUE
20 Index 1
21 NewName "" // formatted name string
22
23 WHILE Index <= LENGTH(Name)
24 ThisChar MID(Name, Index, 1)
25 IF Flag = TRUE THEN
26 NewName NewName & UCASE(ThisChar)
27 IF ThisChar <> SPACECHAR THEN
28 Flag FALSE
29 ENDIF
30 ELSE
31 NewName NewName & ThisChar
32 ENDIF
33 IF ThisChar = SPACECHAR THEN
34 Flag TRUE
35 ENDIF
36 Index Index + 1
37 ENDWHILE
38
39 RETURN NewName
40
41 ENDFUNCTION

© UCLES 2021 9618/23/M/J/21


(a) Complete the trace table below by dry running the function when it is called as follows:

Result Convert("∇in∇a∇∇Cup")

Note: The symbol '∇' has been used to represent a space character.
Use this symbol for any space characters in the trace table.

The first row has been completed for you.

Name Flag Index NewName ThisChar

"∇in∇a∇∇Cup"

[5]

© UCLES 2021 9618/23/M/J/21 [Turn over


12

(b) The pseudocode for Convert() contains a conditional loop.

State a more appropriate loop structure.

Justify your answer.

Loop structure ...........................................................................................................................

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

Justification ...............................................................................................................................

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

...................................................................................................................................................
[2]

(c) Two changes need to be made to the algorithm.

Change 1: Convert to lower case any character that is not the first character after a space.
Change 2: Replace multiple spaces with a single space.

(i) Change 1 may be implemented by modifying one line of the pseudocode.

Write the modified line.

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

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

(ii) Change 2 may be implemented by moving one line of the pseudocode.

Write the number of the line to be moved and state its new position.

Line number ......................................................................................................................

New position ......................................................................................................................

...........................................................................................................................................
[2]

© UCLES 2021 9618/23/M/J/21


Insert

STRING Functions

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


returns leftmost x characters from ThisString

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

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


returns rightmost x characters from ThisString

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

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 "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the lower case equivalent of ThisChar
Alphabetic characters that are not upper case are unchanged.

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

UCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the upper case equivalent of ThisChar
Alphabetic characters that are not lower case are unchanged.

Example: UCASE('a') returns 'A'

TO_UPPER(ThisString : STRING) RETURNS STRING


returns a string formed by converting all characters of ThisString to upper case.

Example: TO_UPPER("Error 803") returns "ERROR 803"

TO_LOWER(ThisString : STRING) RETURNS STRING


returns a string formed by converting all characters of ThisString to lower case.

Example: TO_LOWER("JIM 803") returns "jim 803"

© UCLES 2021 9618/23/INSERT/O/N/21


3

NUM_TO_STR(x : <data type1>) RETURNS <data type2>


returns a string representation of a numeric value.

Note: <data type1> may be REAL or INTEGER


<data type2> may be CHAR or STRING

Example: NUM_TO_STR(87.5) returns "87.5"

STR_TO_NUM(x : <data type1>) RETURNS <data type2>


returns a numeric representation of a string.

Note: <data type1> may be CHAR or STRING


<data type2> may be REAL or INTEGER

Example: STR_TO_NUM("23.45") returns 23.45

IS_NUM(ThisString : STRING) RETURNS BOOLEAN


returns the value TRUE if ThisString represents a valid numeric value.

Example 1: IS_NUM("12.36") returns TRUE


Example 2: IS_NUM("-12.36") returns TRUE
Example 3: IS_NUM("12.3a") returns FALSE

ASC(ThisChar : CHAR) RETURNS INTEGER


returns an integer value (the ASCII value) of ThisChar

Example: ASC('A') returns 65

CHR(x : INTEGER) RETURNS CHAR


returns the character whose integer value (the ASCII value) is x

Example: CHR(87)returns 'W'

NUMERIC Functions

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

RAND(x : INTEGER) RETURNS REAL


returns a real number in the range 0 to x (not inclusive of x).

Example: RAND(87) could return 35.43

© UCLES 2021 9618/23/INSERT/O/N/21 [Turn over

You might also like