COMPUTER SCIENCE 9618
THEORETICAL PART OF PSEUDO-CODE - ARRAYS AND 2-D ARRAYS
9618/21/M/J/25/Q4(a) < 1-D ARRAY >
(a) The outer loop structure used in the algorithm is not the most appropriate one to use.
State the type of loop structure that would be the most appropriate to use and justify why it is the most appropriate. [2]
Loop structure: ………………………………………………………………………………….
Justification: ……………………………………………………………………………………….………………………………………………………………………………………………
Answer: 4(a) MP1 Count-controlled
The number of iterations required is known
9618/22/M/J/25/Q1(d,i,ii,iii) < 2-D ARRAY >
(d) A global array Product is used as part of the pseudocode design being developed to control the production line. Product is used to store the number of rejected items each day.
The following pseudocode statement is used to assign a value to an element of the array:
The lower and upper bound values are shown in the table:
(i) State the number of dimensions of Product. [1]
MARK SCHEME
Two / 2
(ii) State the total number of elements in array Product. [1]
MARK SCHEME
1000
9618/22/M/J/25/Q7(c.i) < 2-D ARRAY >
(c) The programmer decides to amend the customer ID; it will be stored as a STRING instead of an INTEGER. This means that the 2D array Loyalty can no longer be used.
(i) Explain why the 2D array Loyalty can no longer be used. [1]
9618/22/M/J/25/Q7(c.ii) < 1-D ARRAY >
(ii) Explain how a 1D array could be used to store both the loyalty points and the amended customer ID. [2]
9618/23/M/J/25/Q1(a.ii) <ARRAYS>
(ii) State one difference between local and global variables. [1]
9618/23/M/J/25/Q1(a.iii) <ARRAYS>
(iii) State two benefits of using local variables. [2]
9618/23/M/J/24/Q2(a) < 1-D ARRAY>
Q2(a) A program uses a global 1D array of type string and a text file.
An algorithm that forms part of the program is expressed as follows:
• copy the first line from the file into the first element of the array
• copy the second line from the file into the second element of the array
• continue until all lines
in the file have been copied into the array.
Stepwise refinement is applied to the algorithm.
Outline five steps for this algorithm that could be used to produce pseudocode.
Assume there are more elements in the array than lines in the file.
Do not use pseudocode statements in your answer. [5]
9618/23/M/J/24/Q4(b.i) < 1-D ARRAY>
(a) The value zero denotes the split between the two parts of the sequence.
[
The requirement changes and now there may be up to 20 parts.
(i) Identify a suitable data structure that could be used to store the different total values. [2]
9618/23/M/J/24/Q4(b.ii) < 1-D ARRAY>
(ii) Describe three benefits of using the data structure given in part (b)(i).
9618/23/M/J/24/Q5(a) < 1-D ARRAY>
Q5) A program is being designed in pseudocode.
The program contains the following declaration:
DECLARE Data : ARRAY[1:1000] OF STRING
A procedure ArrayInitialise() is written to initialise the values in the array:
Functions FormatA() and FormatB() apply fixed format case changes to the parameter string.
(a) The design of the procedure does not use the most appropriate loop construct.
Suggest a more appropriate construct that could be used and explain your choice. [2]
9618/21/O/N/24/Q6(a) < 1-D ARRAY>
Q6) A factory produces food items. The items must be used within a certain number of days after their production date. The number of days is known as the shelf life. It is different for each type of item but is always a whole number in the range 1 to 21 (inclusive).
The latest date that an item can be used is called the ‘use-by’ date.
A program is needed to produce labels which show the ‘use-by’ date.
Part of the program is a function GetDate() which will:
• take two parameters: a production date and a value representing the shelf life
• return the corresponding ‘use-by’ date.
The program contains a global 1D array DaysInMonth of type integer which stores the number of days in each month (index 1 is January):
Note:
Leap years are not considered
(a) An algorithm uses the array DaysInMonth to calculate a ‘use-by’ date. An alternative design would involve the use of multiple selection statements.
An array-based technique is often used when there is a large number of different values to check and where no pattern exists.
One advantage of using an array-based technique is the speed of execution compared to the use of multiple selection statements.
Give two other advantages of using an array for this type of operation rather than a solution based on multiple selection statements. [2]
9618/22/O/N/24/Q1(d) < 1-D ARRAY>
(d) The new module referred to in part (c) introduces three new variables.
Complete the following table by giving the appropriate data type for each. [3]
MARK SCHEME:
9618/22/O/N/24/Q2(b) < 2-D ARRAY>
(b) The requirements have been changed. Conceal() will now be written as a procedure which will process 100 card numbers each time it is called.
The card numbers will be stored in a 2D array CardNumber. The original string will be stored in column one and the modified string in column two.
(i) Write pseudocode to declare the array.
9618/22/O/N/24/Q6(b) < 1-D ARRAY>
Q6) A shop sells sandwiches and snacks. The owner chooses a ‘daily special’ sandwich which is displayed on a board outside the shop. Each ‘daily special’ has two different fillings and is made with one type of bread.
The owner wants a program to randomly choose the ‘daily special’ sandwich.
The program designer decides to store the possible sandwich fillings in a 1D array of type string.
The array is declared in pseudocode as follows:
DECLARE Filling : ARRAY [1:35] OF STRING
Each element contains the name of one filling.
An example of the first five elements is as follows:
A second 1D array stores the possible bread used:
DECLARE Bread : ARRAY [1:10] OF STRING
Each element contains the name of one type of bread.
An example of the first three elements is as follows:
Both arrays may contain unused elements. The value of these will be an empty string and they may occur anywhere in each array.
A procedure Special() will output a message giving the ‘daily special’ sandwich made from two randomly selected different fillings and one randomly selected bread.
Unused array elements must not be used when creating the ‘daily special’ sandwich.
Using the above examples, the output could be:
"The daily special is Cheese and Onion on Brown bread."
(b) The owner decides that some combinations of fillings do not go well together. For example, anchovies and peanut butter.
Describe how the design could be changed to prevent certain combinations being selected. [2]
MARK SCHEME:
9618/23/O/N/24/Q1(a) < 1-D ARRAY>
Refer to the insert for the list of pseudocode functions and operators.
Q1 (a) The following table contains pseudocode examples.
Each example may contain statements that relate to one or more of the following:
• selection
• iteration (repetition)
• subroutine (procedure or function).
Complete the table by placing one or more ticks ('✓') in each row. [4]
9618/23/O/N/24/Q4(b) < 1-D ARRAY>
Q4) An examination paper has a maximum of 75 marks. One of five pass grades (A to E) is assigned, depending on the mark obtained. The lowest mark for a given grade is known as the grade boundary.
A program is being written to process examination marks.
The five grade boundaries are stored in a global 1D array GB of type INTEGER, for example:
Any paper that achieves a mark within 2 marks of a grade boundary must be checked. Using the given table, a paper with 45 marks would need to be checked.
(b) An alternative algorithm to determine if a paper needs to be checked uses a global 1D array Check, containing 76 elements of type BOOLEAN. The indices of the array are from 0 to 75 (inclusive), corresponding to the range of possible marks.
An element value in Check is TRUE if the index is within 2 marks of a grade boundary. For example, in the case where the C grade boundary is 43 the corresponding part of the Check array would be as follows:
(43) ← The grade boundary for a C grade
(i) The mark for a given paper is stored in variable Mark.
Describe how an algorithm would use the Check array to determine whether this paper should be checked. [2]
9618/21/M/J/23/Q3(a.ii) < 1-D ARRAY>
Q3) Customers collect points every time they make a purchase at a store.
A program is used to manage the points system and the table lists some of the information stored for one customer.
(a) (ii) Describe a data structure that could be used to store the information for all customers. [2]
9618/21/M/J/23/Q6 < 1-D + 2-D ARRAY>
Q6) A video-conferencing program supports up to six users. Speech from each user is sampled and digitised (converted from analogue to digital). Digitised values are stored in array Sample.
The array Sample consists of 6 rows by 128 columns and is of type integer. Each row contains 128 digitised sound samples from one user.
The digitised sound samples from each user are to be processed to produce a single value which will be stored in a 1D array Result of type integer. This process will be implemented by procedure Mix().
A procedure Mix() will:
• calculate the average of each of the 6 sound samples in a column
• ignore sound sample values of 10 or less
• store the average value in the corresponding position in Result
• repeat for each column in array Sample
The diagram uses example values to illustrate the process:
Write pseudocode for procedure Mix().
Assume Sample and Result are global. [6]
9618/22/M/J/23/Q2(c) < 1-D ARRAY>
c) The program will output the day of the week corresponding to MyDOB.
For example, given the date 22/06/2023, the program will output "Thursday".
An algorithm is required. An array will be used to store the names of the days of the week.
Define the array and describe the algorithm in four steps.
Do not use pseudocode statements in your answer.
9618/22/M/J/23/Q3(b) < 1-D ARRAY>
Refer to the insert for the list of pseudocode functions and operators.
Q1) The following pseudocode represents part of the algorithm for a program. Line numbers are for reference only.
(a) The pseudocode contains references to an array.
Complete the table by writing the answer for each row. [3]
9618/22/M/J/23/Q3(b) < 1-D ARRAY>
(b) The pseudocode contains two errors. One error is that variable PCount has not been declared.
Identify the other error and state the line number where it occurs. [2]
9618/22/O/N/23/Q1(c) <1-D ARRAY>
(c) The data that needs to be stored for each customer order in part (a) is not all of the same type.
Describe an effective way of storing this data for many customer orders while the program is running. [3]
9618/23/O/N/23/Q2(b) < 1-D ARRAY>
(b) 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). [2]
9618/23/O/N/23/Q2(c) < 1-D ARRAY>
(c) 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. [2]
9618/22/M/J/22/Q1(c) < 1-D ARRAY>
(c) An identifier table includes the names of identifiers used.
State two other pieces of information that the identifier table should contain. [2]
9618/22/M/J/22/Q8(c) < 1-D ARRAY>
(a) A password has a fixed format, consisting of three groups of four
alphanumeric characters, separated by the hyphen character '-'.
An example of a password is:
"FxAf-3haV-Tq49"
Each password must:
• be 14 characters long
• be organised as three groups of four alphanumeric characters. The groups are separated by hyphen characters
• not include any duplicated characters, except for the hyphen characters.
An algorithm is needed for a new function GeneratePassword(), which will generate and return a password in this format.
Assume that the following modules have already been written:
Note: in a case-sensitive comparison, 'a' is not the same as 'A'.
Describe the algorithm for GeneratePassword().
Do not use pseudocode statements in your answer. [6]
9618/23/M/J/22/Q1(a) < 1-D ARRAY>
Q1a) The following table contains pseudocode examples.
Each example may include all or part of:
• selection
• iteration (repetition)
• assignment.
Complete the table by placing one or more ticks (✓) in each row. [5]
9618/23/M/J/22/Q5(b.i) < 1-D ARRAY>
(b) There may be more records in the array than there are employees in the company. In this case, some records of the array will be unused.
(i) State why it is good practice to have a standard way to indicate unused array elements. [1]
9618/23/M/J/22/Q5(b.ii) < 1-D ARRAY>
(ii) Give one way of indicating an unused record in the Staff array. [1]
9618/23/M/J/22/Q9(b) < 1-D ARRAY>
(b) A global 2D array Secret of type STRING stores the passwords together with the website domain name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns.
Unused elements contain the empty string (""). These may occur anywhere in the array. An example of part of the array is:
Note:
• For security, the passwords are stored in an encrypted form, shown as "●●●●●●●●●●●●" in the example.
• The passwords cannot be used without being decrypted.
• You may assume that the encrypted form of a password will not be an empty string.
Additional modules are defined as follows:
The first three modules have been written.
Write pseudocode for the module AddPassword(). [6]
MARK SCHEME:
9618/21/O/N/22/Q1(b.i) < 1-D ARRAY>
(b) The following pseudocode is part of a program that stores names and test marks for use in other parts of the program.
(i) The pseudocode needs to be changed to allow for data to be stored for up to 30 students. Explain why it would be good practice to use arrays to store the data. [3]
9618/21/O/N/22/Q1(b.ii) < 1-D ARRAY>
(ii) The following pseudocode statement includes array references:
OUTPUT "Student ", Name[Count], " scored ", Mark[Count]
State the purpose of the variable Count and give its data type. [2]
9618/21/O/N/22/Q3 < 1-D ARRAY>
Q3) A 1D array Data of type integer contains 200 elements.
Each element has a unique value.
An algorithm is required to search for the largest value and output it.
Describe the steps that the algorithm should perform.
Do not include pseudocode statements in your answer. [5]
9618/21/O/N/22/Q5 < 1-D ARRAYS >
Q5) A program uses two 1D arrays of type integer. Array1 contains 600 elements and Array2 contains 200 elements.
Array1 contains sample values read from a sensor. The sensor always takes three consecutive samples and all of these values are stored in Array1.
A procedure Summarise() will calculate the average of three consecutive values from Array1 and write the result to Array2. This will be repeated for all values in Array1.
The diagram below illustrates the process for the first six entries in Array1.
Write pseudocode for the procedure Summarise() [5]
MARK SCHEME:
9618/22/O/N/22/Q7(c.i) < 1-D ARRAY >
(c) Two 1D arrays were described at the beginning of the question. Both arrays contain 500 elements.
• Array ErrCode contains integer values that represent an error number in the range 1 to 800.
• Array ErrText contains string values that represent an error description.
The two arrays will be replaced by a single array. A user-defined data type (record structure) has been declared as follows:
(i) State the error in the record declaration. [1]
9618/22/O/N/22/Q7(c.ii) < 1-D ARRAY >
(ii) State two benefits of using the single array of the user-defined data type. [2]
9618/22/O/N/22/Q7(c.iii) < 1-D ARRAY >
(iii) Write the declaration for the single array in pseudocode.
9618/23/O/N/22/Q4(a) < 1-D ARRAY >
Q4a) A program contains a 1D array DataItem with 100 elements.
State the one additional piece of information required before the array can be declared. [1]
9618/23/O/N/22/Q7(b.i) < 1-D ARRAY >
(ii) A new Module RemoveError() will remove a given error number from the array.
Describe the algorithm that would be required. Do not include pseudocode statements in your answer. [3]
MARK SCHEME:
9618/21/M/J/21/Q3(a.i) < 1-D ARRAY >
Q3a) A concert venue uses a program to calculate admission prices and store information about ticket sales.
A number of arrays are used to store data. The computer is switched off overnight and data has to be input again at the start of each day before any tickets can be sold. This process is very time consuming.
(i) Explain how the program could use text files to speed up the process. [2]
MARK SCHEME:
9618/21/M/J/21/Q3(a.ii) < 1-D ARRAY >
(ii) State the characteristic of text files that allow them to be used as explained in part (a)(i). [1]
9618/21/M/J/21/Q7(b) < 1-D ARRAY >
Q7) A program is needed to take a string containing a full name and produce a new string of initials.
Some words in the full name will be ignored. For example, "the", "and", "of", "for" and "to" may all be ignored.
Each letter of the abbreviated string must be upper case.
For example:
The programmer has decided to use a global variable FNString of type STRING to store the full name.
It is assumed that:
• words in the full name string are separated by a single space character
• space characters will not occur at the beginning or the end of the full name string
• the full name string contains at least one word.
The programmer has started to define program modules as follows:
(b) The programmer has decided to use a global ten-element 1D array IgnoreList of type STRING to store the ignored words. Unused elements contain the empty string ("") and may occur anywhere in the array.
A new module AddWord() is needed as follows:
Write a detailed description of the algorithm for AddWord(). Do not include pseudocode statements in your answer. [4]
MARK SCHEME:
9618/22/M/J/21/Q5(a.ii) < 1-D ARRAY >
(ii) The student decides to modify the algorithm so that each element of the array will contain a unique value.
Describe the changes that the student needs to make to the algorithm. [3]
9618/21/O/N/21/Q2(a) < 1-D ARRAY >
Q2a) An algorithm to sort a 1D array into ascending order is described as follows:
• move the largest value to the end
• keep repeating until the array is sorted.
Apply the process of stepwise refinement to this algorithm in order to produce a more detailed description.
Write the more detailed description using structured English. Your explanation of the algorithm should not include pseudocode statements. [6]
9618/22/O/N/21/Q1(b) < 1-D ARRAY >
b) The following pseudocode assigns a value to an element of an array:
ThisArray[n] ← 42
Complete the following table by writing the answer for each row. [3]
9618/22/O/N/21/Q3(a.ii) < 1-D ARRAY >
Q3) A programmer is writing a program to help manage clubs in a school.
Data will be stored about each student in the school and each student may join up to three clubs.
The data will be held in a record structure of type Student.
The programmer has started to define the fields that will be needed as shown in the following table.
(a) (ii) A 1D array Membership containing 3000 elements will be used to store the student data.
Write pseudocode to declare the Membership array. [2]
9618/22/O/N/21/Q3(a.iii) < 1-D ARRAY >
(iii) Some of the elements of the array will be unused.
Give an appropriate way of indicating an unused array element. [1]
9618/22/O/N/21/Q3(a.iv) < 1-D ARRAY >
(iv) Some students are members of less than three clubs.
State one way of indicating an unused club field. [1]





0 Reviews