A computer program is needed to store jobs in order of priority. Each job has a job number (for example, 123) and a priority from 1 to 10, with 1 being the highest priority and 10 the lowest. The program stores the jobs in a global 2D array. The pseudocode declaration for the array is: DECLARE Jobs : ARRAY[0:99, 0:1] OF INTEGER For example: • Jobs [0, 0] stores the job number of the first job. • Jobs [0, 1] stores the priority of the first job. The global variable, NumberOfJobs, stores the number of jobs currently in the array.
- (a)Write program code to declare the global 2D array Jobs and the global variable NumberOfJobs. Save your program as Question1_N22. Copy and paste the program code into part 1(a) in the evidence document.[3]
- (b)The procedure Initialise() stores -1 in each of the array elements and assigns 0 to NumberOfJobs. Write program code for the procedure Initialise(). Save your program. Copy and paste the program code into part 1(b) in the evidence document.[3]
- (c)The procedure AddJob(): • takes a job number and priority as parameters • stores the job in the next free array element • outputs 'Added' if the job was successfully stored in the array • outputs 'Not added' if the job was not successfully stored in the array. Write program code for the procedure AddJob(). Save your program. Copy and paste the program code into part 1(c) in the evidence document.[5]
- (d)The main program should call the procedure Initialise() and then use the AddJob() procedure to store the following jobs in the order given: Job number Priority 12 10 526 9 33 8 12 9 78 1 Write program code for the main program and perform the tasks described. Save your program. Copy and paste the program code into part 1(d) in the evidence document.[2]
- (e)When a new job has been added, the array is sorted into ascending numerical order of priority using an insertion sort. Write program code for the procedure InsertionSort() to sort the data into ascending numerical order of priority. Save your program. Copy and paste the program code into part 1(e) in the evidence document.[5]
- (f)The procedure PrintArray() outputs each job number and priority on a line, for example: 123 priority 1 39 priority 3 120 priority 7 Write program code for the procedure PrintArray(). Save your program. Copy and paste the program code into part 1(f) in the evidence document.[3]
- (g)(i)Amend the main program by writing program code to call procedures InsertionSort() and PrintArray(). Save your program. Copy and paste the program code into part 1(g)(i) in the evidence document.[1]
- (g)(ii)Test your program. Take a screenshot of the output. Copy and paste the screenshot into part 1(g)(ii) in the evidence document.[1]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2022). The mark or mark type is shown in brackets.
- [3] 1 mark per point: (global) 2-D array Jobs with correct identifier (and Integer data type) with 100 elements by 2 elements (global) NumberOfJobs declared as variable (as Integer)
- [3] 1 mark per point: procedure heading (and end where appropriate) and assigns 0 to NumberOfJobs looping through both array element dimensions assigns -1 to all elements
- [5] 1 mark per point (Max 5): Function header (and end where appropriate) with two (integer) parameters Checks if array is full if full outputs "Not added" Storing parameters job number and priority to only the next available array position Incrementing NumberOfJobs Outputting "Added" if successful
- [2] 1 mark per point: Calls Initialise () (in the main program) 5 AddJob calls with correct values as parameters in correct order
- [5] 1 mark per point: Procedure header (and end where appropriate) Outer loop through all 5 elements / number of jobs ... inner loop through array elements ...and comparing priority (second index) ... ...moving the elements up and inserting correctly
- [3] 1 mark per point: procedure heading (and end where appropriate) and outputting all job numbers and priorities Outputting the job and priority for each element on the same line, with a line break between each job ... with 'priority' between job number and priority
- [1] 1 mark per point: calling both subroutines in the main program in the correct order
- [1] 1 mark for added 5 times and jobs in order. 526 and 12 can be reversed Added Added Added Added Added 78 priority 1 33 priority 8 526 priority 9 12 priority 9 12 priority 10
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →