Arrays (Cambridge (CIE) IGCSE Computer Science): Exam Questions

Exam code: 0478 & 0984

51 mins6 questions
11 mark

Tick (✓) one box to show the name of the data structure used to store a collection of data of the same data type.

  • Array

  • Constant

  • Function

  • Variable

23 marks

Describe a one-dimensional array.

Include an example of an array declaration.

32 marks

Explain how indexing could be used to search for a value stored in a one-dimensional array.

415 marks

A one-dimensional (1D) array Days[] contains the names of the days of the week. A two-dimensional (2D) array Readings[] is used to store 24 temperature readings, taken once an hour, for each of the seven days of the week. A 1D array AverageTemp[] is used to store the average temperature for each day of the week.

The position of any day’s data is the same in all three arrays. For example, if Wednesday is in index 4 of Days[], Wednesday’s temperature readings are in index 4 of Readings[] and Wednesday’s average temperature is in index 4 of AverageTemp[]

The temperature readings are in Celsius to one decimal place. Temperatures can only be from –20.0°C to +50.0°C inclusive.

Write a program that meets the following requirements:

  • input and validate the hourly temperatures for one week

  • calculate and store the average temperature for each day of the week

  • calculate the average temperature for the whole week

  • convert all the average temperatures from Celsius to Fahrenheit by using the formula Fahrenheit = Celsius * 9/5 + 32

  • output the average temperature in Celsius and in Fahrenheit for each day

  • output the overall average temperature in Celsius and in Fahrenheit for the whole week.

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.

All data output must be rounded to one decimal place

You will need to initialise and populate the array Days[] at the start of the program

515 marks

A two-dimensional (2D) array Account[] contains account holders’ names and passwords for a banking program.

A 2D array AccDetails[] has three columns containing the following details:

  • column one stores the balance – the amount of money in the account, for example 250.00

  • column two stores the overdraft limit – the maximum total amount an account holder can borrow from the bank after the account balance reaches 0.00, for example 100.00

  • column three stores the withdrawal limit – the amount of money that can be withdrawn at one time, for example 200.00

The amount of money in a bank account can be negative (overdrawn) but not by more than the overdraft limit.
For example, an account with an overdraft limit of 100.00 must have a balance that is greater than or equal to –100.00

Suitable error messages must be displayed if a withdrawal cannot take place, for example if the overdraft limit or the size of withdrawal is exceeded.

The bank account ID gives the index of each account holder’s data held in the two arrays. For example, account ID 20’s details would be held in:
Account[20,1] and Account[20,2] AccDetails[20,1], AccDetails[20,2] and AccDetails[20,3]

The variable Size contains the number of accounts

The arrays and variable Size have already been set up and the data stored

Write a program that meets the following requirements:

  • checks the account ID exists and the name and password entered by the account holder match the name and password stored in Account[] before any action can take place

  • displays a menu showing the four actions available for the account holder to choose from:

    • display balance

    • withdraw money

    • deposit money

    • exit

  • allows an action to be chosen and completed. Each action is completed by a procedure with a parameter of the account ID.

You must use pseudocode or program code and add comments to explain how your code works. All inputs and outputs must contain suitable messages.

You only need to declare any local arrays and local variables that you use.

You do not need to declare and initialise the data in the global arrays Account[] and AccDetails[] and the variable Size

615 marks

The one-dimensional (1D) array Clubs[] is used to store the names of 12 cricket clubs in a local sports league.

The two-dimensional (2D) array Statistics[][] is used to store, for each cricket club, the number of:

  • matches won

  • matches drawn

  • matches lost.

The 1D array Points[] is used to store the total number of points each cricket club has been awarded.

The position of any cricket club’s data is the same in all three arrays. For example, the data in index 2 of Statistics[] and index 2 of Points[] belongs to the cricket club in index 2 of Clubs[].

The variable Matches stores the number of matches played by each team. Each team plays the same number of matches.

Points are awarded for:

  • a win – 12 points

  • a draw – 5 points

  • a loss – 0 points.

Write a program that meets the following requirements:

  • allows the number of matches played to be input and stored, with a maximum of 22 matches

  • validates the number of matches played

  • allows the names of the cricket clubs to be input and stored

  • allows the number of matches won, drawn and lost to be input and stored for each team

  • validates the number of matches won, drawn or lost against the number of matches played

  • asks the user to re-enter the number of matches won, drawn or lost if the total does not match the number of matches played

  • calculates and stores the total number of points for each club

  • finds the cricket club or clubs with the highest number of points

  • outputs the name or names of the winning club or clubs, the number of wins and the total number of points awarded.

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

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

All inputs and outputs must contain suitable messages.