9618/42

Computer Science 9618/42May/June 2023

Cambridge A-Level · Practical · worked solutions for every part, with the mark scheme

3
questions
75
marks
150
minutes

Topics Programming Paradigms (Procedural and Object-oriented) · Algorithms and Abstract Data Types · File Processing and Exception Handling

Q1Programming Paradigms (Procedural and Object-oriented)Algorithms and Abstract Data TypesFree sample

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

Two source files are used to answer Question 3. The files are called Employees.txt and HoursWeek1.txt

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 1D array needs to store the names of 10 animals.

(a)

Write program code to declare the global string array Animals to store 10 items.

Save your program as Question1_J2023.

Copy and paste the program code into part 1(a) in the evidence document.

2M
(b)

The main program needs to store the following animals in the array:

horse
lion
rabbit
mouse
bird
deer
whale
elephant
kangaroo
tiger

Write program code to store these animal names in the array.
The names must be in lower case and stored in the order given in the list.

Save your program.

Copy and paste the program code into part 1(b) in the evidence document.

2M
(c)

The following pseudocode procedure sorts the array into a descending alphabetical order using only the first character in each animal name.

The function LENGTH(DataArray) returns the number of elements in the array DataArray.

The function MID(String, Start, Quantity) returns Quantity number of characters from String starting at index Start. The first character in the string is index 0, for example:

MID("tiger", 0, 2) will return "ti"

There are four incomplete statements in the procedure.

PROCEDURE SortDescending()

   DECLARE ArrayLength : INTEGER

   DECLARE Temp : STRING

   ArrayLength ← LENGTH(Animals)

   FOR X ← 0 TO ArrayLength - 1

      FOR Y ← ..................... TO ArrayLength - X - 1

         IF MID(Animals[Y], 0, 1) < MID(Animals[.....................], 0, 1) THEN

            Temp ← Animals[.....................]

            Animals[Y] ← Animals[Y + 1]

            Animals[Y + 1] ← .....................

         ENDIF

      NEXT Y

   NEXT X

ENDPROCEDURE

Write program code for the procedure SortDescending().

Save your program.

Copy and paste the program code into part 1(c) in the evidence document.

6M
(d)
(i)

Write program code to amend the main program to:

  • call the procedure SortDescending()
  • output the sorted contents of the array with each animal name on a new line.

Save your program.

Copy and paste the program code into part 1(d)(i) in the evidence document.

3M
(ii)

Test your program.

Take a screenshot of the output.

Save your program.

Copy and paste the screenshot into part 1(d)(ii) in the evidence document.

1M

The rest of this paper

2 more questions
  • Q2Programming Paradigms (Procedural and Object-oriented) · Algorithms and Abstract Data Types28M
  • Q3Programming Paradigms (Procedural and Object-oriented) · File Processing and Exception Handling · Algorithms and Abstract Data Types33M
Loading the full paper…