0% found this document useful (0 votes)
4 views8 pages

Data Check : 9618/21/M/J/24 © UCLES 2024

The document outlines pseudocode requirements for functions that process arrays and triangles, including calculating sums of odd and even indexed elements and determining if three points form a right-angled triangle. It also describes a module for processing student pseudocode projects, including removing comments from lines and creating new files for each project stage. Additionally, it addresses potential issues with a square root function's accuracy in the context of right-angled triangle validation.
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)
4 views8 pages

Data Check : 9618/21/M/J/24 © UCLES 2024

The document outlines pseudocode requirements for functions that process arrays and triangles, including calculating sums of odd and even indexed elements and determining if three points form a right-angled triangle. It also describes a module for processing student pseudocode projects, including removing comments from lines and creating new files for each project stage. Additionally, it addresses potential issues with a square root function's accuracy in the context of right-angled triangle validation.
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/ 8

8

4 A global 1D array Data contains 100 elements of type integer.

A function Check() will:

• total the element values in odd index locations (1, 3, 5 ... 97, 99)
• total the element values in even index locations (2, 4, 6 ... 98, 100)
• return one of three strings ‘Odd’, ‘Even’ or ‘Same’ to indicate which total is the greater, or
whether the totals are the same.

Write pseudocode for the function Check().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© UCLES 2024 9618/21/M/J/24


12

6 Three points on a grid form a triangle with sides of length A, B and C as shown in the example:

10
9
8
7
6
5 B C
4
3
2 A
1
x
0 1 2 3 4 5 6 7 8 9 10

A triangle is said to be right-angled if the following test is true (where A is the length of the longest
side):

A2 = B2 + C2

A2 means A multiplied by A, for example 32 means 3 × 3 which evaluates to 9

You can calculate A2, B2 and C2 by using the coordinates of the endpoints of each line.

For example, B2 is calculated as follows:

10
9
8
7
P2
6 (x2, y2)
5 B
4
3
P1
2 (x1, y1)
1
x
0 1 2 3 4 5 6 7 8 9 10

The endpoints, P1 and P2, have the coordinates (3, 2) and (6, 6).

The value B2 is given by the formula:

B2 = (x1 − x2)2 + (y1 − y2)2

In this example:

B2 = (3 − 6)2 + (2 − 6)2
B2 = (–3)2 + (–4)2
B2 = 9 + 16
B2 = 25

© UCLES 2024 9618/21/M/J/24


13

(a) A function IsRA() will:

• take three sets of integers as parameters representing the coordinates of the three
endpoints that form a triangle
• return TRUE if the endpoints form a right-angled triangle, otherwise return FALSE.

In pseudocode, the operator ‘^’ represents an exponent, which is the number of times a value
is multiplied by itself. For example, the expression Value2 may be written in pseudocode as
Value ^ 2

Complete the pseudocode for the function IsRA().

FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS BOOLEAN

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ENDFUNCTION
[6]

© UCLES 2024 9618/21/M/J/24 [Turn over


14

(b) The test used to check if a triangle is right-angled can be written in two ways:

A2 = B2 + C2

or

A = √(B2 + C2)

The symbol √ represents the square root operation. For example, √81 = 9

A new function SQRT() is written to perform the square root operation. The function takes an
integer number as a parameter and returns a positive real value representing the square root
of the number.

During testing it is found that the SQRT() function returns a value that is only accurate to
4 decimal places.

For example, SQRT(25) returns 5.0000125 rather than the correct value of 5.0

The function IsRA() from part (a) is modified to use the new SQRT() function to test if a
triangle is right-angled.

Describe a problem that might occur when using the modified IsRA() function and suggest
a solution that still allows the SQRT() function to be used.

Problem ....................................................................................................................................

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

Solution .....................................................................................................................................

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

© UCLES 2024 9618/21/M/J/24


18

8 A teacher is designing a program to process pseudocode projects written by her students.

Each student project is stored in a text file.

The process is split into a number of stages. Each stage performs a different task and creates a
new file named as shown:

File name Comment

MichaelAday_src.txt student project file produced by student Michael Aday

MichaelAday_S1.txt file produced by stage 1

MichaelAday_S2.txt file produced by stage 2

The teacher has defined the first program module as follows:

Module Description
DeleteComment() • called with a parameter of type string representing a line of
pseudocode from a student’s project file
• returns the line after removing any comments

Note on comments:
A comment starts with two forward slash characters and includes all the
remaining characters on the line.

The following example shows a string before and after the comment has
been removed:

Before: IF X2 > 13 THEN //check if limit exceeded


After: IF X2 > 13 THEN

© UCLES 2024 9618/21/M/J/24


19

(a) Complete the pseudocode for module DeleteComment().

FUNCTION DeleteComment(Line : STRING) RETURNS STRING

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ENDFUNCTION
[8]

© UCLES 2024 9618/21/M/J/24 [Turn over


20

(b) A second module is defined:

Module Description
Stage_1() • called with a parameter of type string representing a student name
• creates a new stage 1 file
• copies each line from the student’s project file to the stage 1 file after
removing any comment from each line
• does not write blank lines to the stage 1 file
• returns the number of lines written to the stage 1 file

Write pseudocode for module Stage_1().

Module DeleteComment() must be used in your solution.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...................................................................................................................................................
© UCLES 2024 9618/21/M/J/24
21

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

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

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

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

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

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

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

............................................................................................................................................. [7]

© UCLES 2024 9618/21/M/J/24

You might also like