CAMBRIDGE IGCSE COMPUTER SCIENCE
Summer 2023 · Paper 23 · Question 11 · 15 marks
← 0478 CS Hub Paper 23 · Summer 2023 0478 / Paper 2 Question 11 15 MARKS
15-mark question lab · start here

From a 2D contacts array to a menu-driven phone book.

Build the solution in a sensible order: decode the requirements, plan the array and its working variables, start the menu loop, validate the choice, add the batch within the five-and-100 caps, bubble-sort by contact name, then display and delete the whole array. Learn the reasoning before revealing the complete program.

2D array of stringsMenu-driven programValidation loopsBubble sortCaps: 5 and 10015 marks

Learning targets

By the end, you should be able to explain the algorithm before writing it.

Lesson overview

01 · Understand

Identify the given 2D array Contacts[] — names as last name, first name in column 1, telephone numbers in column 2 — the variable CurrentSize, the 100-contact capacity and the requirements hidden in the bullet list.

02 · Construct

Build the menu loop with a validated choice, then the add branch: ask how many new contacts, enforce the 1-to-5 and 100-contact caps, store each name and number in the next free rows, update CurrentSize and bubble-sort by contact name.

03 · Complete

Output the whole of the array with a labelling header when the user chooses display, and delete the contents of every cell when the user chooses delete.

!

How Cambridge awards the marks: the mark scheme gives AO2 a maximum of 9 marks and AO3 a maximum of 6 marks. It lists requirements R1–R5, but does not assign a separate fixed mark total to each R requirement. The stage-to-mark links in this guide show alignment, not invented stage marks.

Source question

Read the whole question first

Do not begin coding after the first paragraph. The two-column array, the two caps of five and 100, the conditional sort and the delete-all branch all affect the structure of your solution.

Question 11 · 15 marks
Cambridge IGCSE Computer Science · 0478/23 · Question 11

A two-dimensional (2D) array Contacts[] is used to store names and telephone numbers. All the data is stored as strings. The array must have the capacity to store 100 contacts in the form of:

  • column 1 – contact names as: last name, first name
    • for example: Smith, John
  • column 2 – telephone numbers.

The variable CurrentSize shows how many contacts are in the array.

Write a program that meets the following requirements:

  • display a menu of choices:
    • enter new contact details
    • display all the contact details
    • delete all the contact details
  • validate the menu input
  • allow up to a maximum of five new contacts to be added to the array at any one time
  • do not allow more than 100 contacts in total
  • after new contacts have been added, sort the array by contact name, as long as there are at least two contacts in the array
  • output the whole of the array
  • delete the contents of the array.

You must use pseudocode or program code and add comments to explain how your code works.

You do not need to declare any arrays, variables or constants; you may assume that this has already been done.

All inputs and outputs must contain suitable messages.

You do not need to initialise the data in the array Contacts[] and the variable CurrentSize

Before you move on

These are the five required techniques identified by the Cambridge mark scheme.

Mark-scheme map
R1

Output the menu of choices and input the user’s choice with prompts — output and input with messages.

R1

Validate the menu input with a range check on 1 to 3, re-asking with suitable messages until a legal choice is entered.

R2

Input the number of new entries within its limits — at least 1 and at most 5 at any one time, and never more than 100 contacts in total — updating CurrentSize.

R2

Input the new contact data into the array and bubble-sort it by contact name whenever at least two contacts are stored.

R3

Output the whole contents of the array with labelling and delete the contents of every cell.

Use the tabs along the top to work through the seven stages. The complete solution is kept in its own tab, and the interactive visualisation is the final tab.