Construct a trace table for the following algorithm: [6]
N = 5
S = 0
R = 0
loop while N > 0
A = N mod 3
if A = 0
then
S = S − N
elseif A = 1
then
S = S + N
else S = S + 1
end if end if R = R + S
N = N − 1
end loop
output ('The result is ', R)
Construct a trace table for the following algorithm: [6]
K = 1
S = 0
Z = 0
loop while K < 6
A = K mod 3
if A = 2
then
S = S + K
elseif A = 1
then
S = S − K
else S = S + 1
end if end if Z = Z + S
K = K + 1
end loop
output ('The result: ', Z)
Construct a trace table for the following algorithm:
A = 20
B = 12
loop while B > 0
TEMP = B
B = A mod B
A = TEMP
end loop
output (A)
[4]
Given the one-dimensional array NAMES:
construct a trace table for the following algorithm: [4]
K=3
loop while K>=0
A=K mod 3
output (NAMES[A])
K=K−1
end while
Construct a trace table for the following algorithm:
N = 1216
X = 0
loop while N > 0
X = X + N mod 10
N = N div 10
end loop
output (X)
Deduce the purpose of this algorithm. [2]
Given the integer array DATA:
and the following algorithm:
K = 5
A = 1
B = 0
while K >= 0
if DATA[K] mod 2 < 1
then
A = A * DATA[K]else B = B + 1
end if K = K - 1
end whileoutput(A)
output(B)
A teacher would like a simple program to store the names, marks and grades of students in a set of three parallel one-dimensional arrays called NAME[], MARK[] and GRADE[] .
The grade boundaries for the individual grades are shown below:
The class has 30 students.
(a) Construct an algorithm using pseudocode to take the marks that have been stored in MARK[], convert them into the appropriate grade and store the calculated grades in GRADE[].[5]
(b) Outline how the name, mark and grade in the three arrays correspond to the same student.[2]
(c) Construct an algorithm using pseudocode to output the names and grades of all students who achieve a grade of Merit or Distinction.[3]
(d) Explain how you would change your algorithm in part (c) to allow a user to choose a grade and output the names and marks of the students who have achieved this grade.[3]
A company has 600 employees whose names are currently stored using a collection called NAMES. The names are stored as surname, first name. For example:
(a) Construct a pseudocode algorithm that will store the surnames in one array and first names in another.[4]
The names in the collection are kept in a random order. However, it would be more useful if they were kept in alphabetical order.
(b) Construct a pseudocode algorithm that will sort the surnames into alphabetical order using the bubble sort method. The order of the first names must also be changed so that they keep the same index as their corresponding surname.[5]
The company’s staff list is now organized in the arrays in alphabetical order.
A binary search was used to find a specific name in the array.
(c) Describe the process a binary search would follow to find a record in the surname array.[4]
There are 200 students in a school. Their names are held in the one-dimensional string array STUDENTS.
The one-dimensional integer array MARKS stores marks (0–100 inclusive) that students scored in an examination.
Figure 1: Example data stored in the two arraysSTUDENTSandMARKS
The one-dimensional integer array GRADES will be used to store the grades awarded to students based on their examination marks.
In Figure 1, Boris Mount scored 88 marks. His grade will be stored in GRADES[1].
Consider the following algorithm that the school currently uses for awarding grades:
loop K from 0 to 199
GRADES[K]= 1 + (MARKS[K] div 10)
if GRADES[K]>= 7 then
GRADES[K]= 7
end ifend loop
(a.i) Determine the value of GRADES[0].[1]
(a.ii) Determine the value of GRADES[1].[1]
(a.iii) Determine the value of GRADES[2].[1]
(a.iv) State the minimum mark necessary to achieve Grade 7.[1]
Grade 1 is a failing grade. Each student who receives a failing grade must re-sit the examination.
(b) Construct an algorithm in pseudocode to fill the one-dimensional string array RESIT with the names of students who must re-sit the examination.[4]
A different method of awarding grades is proposed for the examinations. This new grading system will use three grades represented by the letters A, B, and C.
Grades A, B, or C will be calculated as follows:
The average mark for all students is calculated.
Grade A is awarded if an individual student’s marks are more than 20 marks above the average mark for all students.
Grade B is awarded if an individual student’s marks are within 20 marks of the average mark for all students.
Grade C is awarded if an individual student’s marks are more than 20 marks below the average mark for all students.
For example, if the average mark for all students is 49.5:
Grade A is awarded if a student’s marks are greater than 69.5.
Grade B is awarded if a student’s marks are in the range from 29.5 to 69.5 inclusive.
Grade C is awarded if a student’s marks are less than 29.5.*
(c) Construct an algorithm in pseudocode to calculate and store the letter grades of all students in the one-dimensional string array LETTERGRADES as described.[7]