9618/23 · Oct/Nov 2023
Download PDFRefer to the insert for the list of pseudocode functions and operators. A program is being developed in pseudocode before being converted into a programming language.
The following table shows four valid pseudocode assignment statements. Complete the table by giving the data type that should be used to declare the variable underlined in each assignment statement.
Other variables in the program have example values as shown:
| Active | TRUE |
| Fraction | |
| Code | "Ab12345" |
Complete the table by evaluating each expression using the example values.
| Fraction >= 0.2 AND NOT Active | |
| INT((Fraction * 100) + 13.3) | |
| STR_TO_NUM(MID(Code, 4, 2)) + 5 | |
| LENGTH("TRUE" & Code) |
The program makes use of complex statistical functions. The required functions are not built-in to the programming language and are too complicated for the programmer to write. One solution would be to employ another programmer who has experience of writing these functions, as there is no time to train the existing programmer. State one other way that these functions may be provided for inclusion in the program.
The hardware that runs the program is changed and the program needs to be modified so that it works with the new hardware. Identify the type of maintenance that this represents and give one other reason why this type of maintenance may be needed. Type .......................................................................................................................................... Reason .....................................................................................................................................
Data is a 1D array of integers, containing 30 elements. All element values are unique.

An algorithm will output the index of the element with the smallest value. Draw a program flowchart to represent the algorithm.
The 30 data values could have been stored in separate variables rather than in an array. Explain the benefits of using an array when designing a solution to part (a).
The requirement changes. Array Data needs to hold 120 elements and each value may include a decimal place. Write a pseudocode statement to declare the modified array.
The diagram represents a queue Abstract Data Type (ADT). The organisation of this queue may be summarised as follows: • The FrontOfQueue pointer points to the next data item to be removed. • The EndOfQueue pointer points to the last data item added.
| D4 |
| D1 |
| D2 |
The queue is implemented using three variables and a 1D array of eight elements as shown. The variable NumItems stores the number of items in the queue. The pointer variables store indices (index numbers) of the array.
Complete the diagram to represent the state of the queue as shown above.
A module AddTo() will add a value to the queue by manipulating the array and variables in part (a). The queue implementation is circular. When pointers reach the end of the queue, they will ‘wrap around’ to the beginning. Before a value can be added to the queue, it is necessary to check the queue is not full. The algorithm to add a value to the queue is expressed in six steps. Complete the steps. 1. If NumItems .............................. then jump to step 6. 2. Increment ................................... 3. If ................................................. then set EndOfQueue to .............................. 4. Increment ................................... 5. Set the ............................ at the index stored in ........................... to the ............................ being added. 6. Stop.
A procedure RandList() will output a sequence of 25 random integers, where each integer is larger than the previous one.
Write pseudocode for procedure RandList().
Procedure RandList() is modified so that the random numbers are also written into a 1D array Result. A new module is written to confirm that the numbers in the array are in ascending order. This module contains an IF statement that performs a comparison between elements: IF (Result[x + 1] = Result[x]) OR (Result[x] > Result[x + 1]) THEN Sequence ← FALSE ENDIF Write a simplified version of the conditional clause.
A global 1D array of integers contains four elements, which are assigned values as shown: Mix[1] ← 4 Mix[2] ← 2 Mix[3] ← 3 Mix[4] ← 5 A procedure Process() manipulates the values in the array. The procedure is written in pseudocode as follows: PROCEDURE Process(Start : INTEGER) DECLARE Value, Index, Total : INTEGER Index ← Start Total ← 0 WHILE Total < 20 Value ← Mix[Index] Total ← Total + Value IF Index < 4 THEN Mix[Index] ← Mix[Index] + Mix[Index+1] ELSE Mix[Index] ← Mix[Index] + Mix[1] ENDIF Index ← (Value MOD 4) + 1 ENDWHILE Mix[1] ← Total * Index ENDPROCEDURE Complete the trace table on the opposite page by dry running the procedure when it is called as follows: CALL Process(2)
A function TestNum() will take a six-digit string as a parameter. The function will test whether the string meets certain conditions and will return an integer value as follows:
| The last three digits are the same but non-zero. | "253444" | |
| The last three digits are zero. | "253000" | |
| The first three and last three digits are the same. | "410410" |
The function will return the highest possible value for the given string. If the string does not meet any of the conditions, zero is returned. Write pseudocode for function TestNum(). Assume that the parameter is valid.
A structure chart shows the modular structure of a program: [Structure Chart showing Module-A() calling Sub-Y1() with parameter T1, calling Sub-Y2() with parameter SA, and calling Sub-9() with parameter RA and return value RB, with a curved arrow looping across the module calls]

Explain the meaning of the curved arrow symbol which begins and ends at Module-A().
The structure chart shows that Sub-9() is a function. A Boolean value is returned by Sub-9() for processing by Module-A(). The original parameter RA is of type integer and RB is of type string. A record type MyType will be defined with three fields to store the values passed between the two modules. Write pseudocode to define MyType.
The design is modified and Sub-9() is changed to a procedure. The procedure will be called with a single parameter of type MyType. Write the pseudocode header for procedure Sub-9().
A class of students are developing a program to send data between computers. Many computers are connected together to form a wired network. Serial ports are used to connect one computer to another. Each computer: • is assigned a unique three-digit ID • has three ports, each identified by an integer value • is connected to between one and three other computers. Messages are sent between computers as a string of characters organised into fields as shown: <STX><DestinationID><SourceID><Data><ETX>
| STX | a single character marking the start of the message (ASCII value 02) |
| DestinationID | three numeric characters identifying the destination computer |
| SourceID | three numeric characters identifying the source computer |
| Data | a variable length string containing the data being sent (Minimum length is 1 character) |
| ETX | a single character marking the end of the message (ASCII value 03) |
For example, the following message contains the data "Hello Jack" being sent from computer "202" to computer "454": <STX>"454202Hello Jack"<ETX> Each computer will run a copy of the same program. Each program will contain a global variable MyID of type string which contains the unique ID of the computer in which the program is running. The first two program modules are defined as follows:
| ReceiveFile() |
Write pseudocode for module ReceiveFile(). Module GetData() has already been written and must be used.
The use of the string "****" as explained in the module description for ReceiveFile() may cause a problem. Explain the problem and suggest a solution. Problem .................................................................................................................................... Solution .....................................................................................................................................
Two new modules are defined, which will allow two users to exchange messages.
| Chat() |
Reminders: • Each program contains a global variable MyID of type string which contains the unique ID of the computer in which the program is running. • Messages are sent between computers as a string of characters organised into fields as shown: <STX><DestinationID><SourceID><Data><ETX> Write pseudocode for module Chat(). Modules GetData() and Transmit() must be used.
Module GetData() returns the data field from a message that has been received. If no message is available, the module waits until one has been received. Explain the limitation of this on module Chat() from part (c). Describe a modification to GetData() to address this limitation. Limitation .................................................................................................................................. Modification ..............................................................................................................................






