Computer Science 9618/42 — May/June 2022
Cambridge A-Level · Practical · worked solutions for every part, with the mark scheme
Topics Programming Paradigms (Procedural and Object-oriented) · Algorithms and Abstract Data Types · Recursion · File Processing and Exception Handling
Open the document evidence.doc
Make sure that your name, centre number and candidate number will appear on every page of this document. This document must contain your answers to each question.
Save this evidence document in your work area as:
evidence_ followed by your centre number_candidate number, for example: evidence_zz999_9999
A class declaration can be used to declare a record.
If the programming language used does not support arrays, a list can be used instead.
A program needs to use a stack data structure. The stack can store up to 10 integer elements.
A 1D array StackData is used to store the stack globally. The global variable StackPointer points to the next available space in the stack and is initialised to 0.
Write program code to declare the array and pointer as global data structures. Initialise the pointer to 0.
Save your program as Question1_J22.
Copy and paste the program code into part 1(a) in the evidence document.
Write a procedure to output all 10 elements in the stack and the value of StackPointer.
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
The function Push() takes an integer parameter and returns FALSE if the stack is full. If the stack is not full, it puts the parameter value on the stack, updates the relevant pointer and returns TRUE.
Write program code for the function Push().
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
Edit the main program to test the Push() function. The main program needs to:
- allow the user to enter 11 numbers and attempt to add these to the stack
- output an appropriate message when a number is added to the stack
- output an appropriate message when a number is not added to the stack if it is full
- output the contents of the stack after attempting to add all 11 numbers.
Save your program.
Copy and paste the program code into part 1(d)(i) in the evidence document.
Test your program from part 1(d)(i) with the following 11 inputs:
11 12 13 14 15 16 17 18 19 20 21
Take a screenshot to show the output.
Copy and paste the screenshot into part 1(d)(ii) in the evidence document.
The function Pop() returns -1 if the stack is empty. If the stack is not empty, it returns the element at the top of the stack and updates the relevant pointer.
Write program code for the function Pop().
Save your program.
Copy and paste the program code into part 1(e)(i) in the evidence document.
After the code you wrote in the main program for part 1(d)(i), add program code to:
- remove two elements from the stack using
Pop() - output the updated contents of the stack.
Test your program and take a screenshot to show the output.
Copy and paste the screenshot into part 1(e)(ii) in the evidence document.
The rest of this paper
2 more questions- Q2Programming Paradigms (Procedural and Object-oriented) · Algorithms and Abstract Data Types · Recursion23M
- Q3Programming Paradigms (Procedural and Object-oriented) · File Processing and Exception Handling27M