Arrays fgq4Smn7Hgn78jrw
Arrays fgq4Smn7Hgn78jrw
Exam Questions
Arrays
Arrays
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Easy Questions
1 Tick (✓) one box to show the name of the data structure used to store a collection of data of the same data type.
A. Array
B. Constant
C. Function
D. Variable
Answer
A is correct as an array is described as a data structure used to store a collection of data of the same data type [1
mark]
B is incorrect as a constant is an identifier set once in the lifetime of a program
(1 mark)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
Medium Questions
1 Describe a one-dimensional array.
Answer
(3 marks)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
Hard Questions
1 Explain how indexing could be used to search for a value stored in a one-dimensional array.
Answer
(2 marks)
2 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.
calculate and store the average temperature for each day of the 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.
You will need to initialise and populate the array Days[] at the start of the program
Answer
The provided solutions are just two of many possible solutions; as long as your code effectively addresses the problem, it
is equally valid and can receive full marks.
Pseudocode
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
// meaningful identifiers and appropriate data structures for
// all data required
DECLARE Days : ARRAY[1:7] OF STRING
DECLARE Readings : ARRAY[1:7, 1:24] OF REAL
DECLARE AverageTemp : ARRAY[1:7] OF REAL
DECLARE WeekLoop : INTEGER
DECLARE DayLoop : INTEGER
DECLARE InTemp : REAL
DECLARE TotalDayTemp : REAL
DECLARE TotalWeekTemp : REAL
DECLARE AverageWeekTemp : REAL
// initial population of Days[] array
// input and a loop are also acceptable
Days[1]← "Sunday"
Days[2] ← "Monday"
Days[3] ← "Tuesday"
Days[4] ← "Wednesday"
Days[5] ← "Thursday"
Days[6] ← "Friday"
Days[7] ← "Saturday"
// input temperatures inside nested loop
FOR WeekLoop ← 1 TO 7
TotalDayTemp←0
FOR DayLoop ← 1 TO 24
OUTPUT "Enter temperature ", DayLoop, " for ", Days[WeekLoop]
INPUT InTemp
// validation of input for between -20 and +50 inclusive
WHILE InTemp < -20.0 OR InTemp > 50.0 DO
OUTPUT "Your temperature must be between -20.0 and +50.0 inclusive. Please try again"
INPUT InTemp
ENDWHILE
Readings[WeekLoop, DayLoop] ← InTemp
// totalling of temperatures during the day
TotalDayTemp ← TotalDayTemp + ROUND(InTemp, 1)
NEXT DayLoop
// average temperature for the day
AverageTemp[WeekLoop] ← ROUND(TotalDayTemp / 24,1) NEXT WeekLoop
// calculate the average temperature for the week
TotalWeekTemp ←0
FOR WeekLoop ← 1 TO 7 TotalWeekTemp ← TotalWeekTemp + AverageTemp[WeekLoop]
NEXT WeekLoop
AverageWeekTemp ← ROUND(TotalWeekTemp / 7,1)
// outputs in Celsius and Fahrenheit
FOR WeekLoop ← 1 TO 7
OUTPUT "The average temperature on ", Days[WeekLoop], " was ", AverageTemp[WeekLoop], " Celsius and ",
ROUND(AverageWeekTemp 9 / 5 + 32), 1, " Fahrenheit"
NEXT WeekLoop
OUTPUT "The average temperature for the week was ", AverageWeekTemp," Celsius and ", ROUND(AverageWeekTemp 9 / 5 + 32, 1),"
Fahrenheit"
Python
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 5
total_week_temp = 0.0
average_week_temp = 0.0
average_week_temp = round(total_week_temp / 7, 1)
1. Techniques:
a. Input and store hourly temperatures and validation of input temperatures for each day (with prompts,
range check and (nested)iteration)
b. Calculate, round to one decimal place and store daily average temperatures and calculate the weekly
average temperature rounded to one decimal place (iteration, totalling and rounding)
c. Convert all average temperatures to Fahrenheit (to one decimal place) and output the average
temperatures in both Celsius and Fahrenheit. Output with appropriate messages. (output and rounding)
2. Data structures:
The names underlined must match those given in the scenario
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 6
Examiner Tips and Tricks
All criteria stated for the scenario have been covered by the use of appropriate programming techniques
The data structures used store all the data that is required by the scenario
All the data structures used have meaningful names
Solution logically performs all the tasks given in the scenario
(15 marks)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 7
3 A two-dimensional (2D) array Account[] contains account holders’ names and passwords for a banking program.
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 arrays and variable Size have already been set up and the data stored
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
Answer
The provided solutions are just two of many possible solutions; as long as your code effectively addresses the problem, it
is equally valid and can receive full marks.
Pseudocode
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 8
// Procedures to be called PROCEDURE CheckDetails(AccID : INTEGER)
DECLARE Name, Password : STRING // local variables
Valid FALSE
IF AccID <0 OR AccID > Size
THEN
OUTPUT "Invalid Account Number"
ELSE
OUTPUT "Please Enter Name "
INPUT Name
OUTPUT "Please Enter Password "
INPUT Password
IF Name <> Account[AccID,1] OR Password <> Account[AccID,2]
THEN
OUTPUT "Invalid name or password"
ELSE
Valid True
ENDIF
ENDIF
ENDPROCEDURE
PROCEDURE Balance(AccID : INTEGER)
OUTPUT "Your balance is ", AccDetails[AccID,1]
ENDPROCEDURE
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 9
IF Valid
THEN
REPEAT
OUTPUT "Menu"
OUTPUT "1. display balance"
OUTPUT "2. withdraw money"
OUTPUT "3. deposit money"
OUTPUT "4. exit"
OUTPUT "please choose 1, 2, 3 or 4"
INPUT Choice
CASE OF Choice
1 : Balance(AccountNumber)
2 : Withdrawal(AccountNumber)
3 : Deposit(AccountNumber)
4 : Exit TRUE
OTHERWISE OUTPUT "Invalid choice"
ENDCASE
UNTIL Choice = 4
ELSE
OUTPUT "Invalid account number "
ENDIF
Python
AccDetails = {
1: [500.00, 100.00, 300.00], # [Balance, Overdraft, WithdrawalLimit]
2: [800.00, 200.00, 500.00], # Add more as needed
}
Valid = False
Exit = False
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 10
print("Amount greater than cash available")
elif Amount <= AccDetails[AccID][2] and Amount <= AccDetails[AccID][0] + AccDetails[AccID][1]:
AccDetails[AccID][0] -= Amount
print(f"Withdrawal successful. New balance: {AccDetails[AccID][0]}")
break
# Main program
AccountNumber = int(input("Please enter your account number: "))
CheckDetails(AccountNumber)
if Valid:
while not Exit:
print("\nMenu")
print("1. Display balance")
print("2. Withdraw money")
print("3. Deposit money")
print("4. Exit")
Choice = int(input("Please choose 1, 2, 3 or 4: "))
if Choice == 1:
Balance(AccountNumber)
elif Choice == 2:
Withdrawal(AccountNumber)
elif Choice == 3:
Deposit(AccountNumber)
elif Choice == 4:
Exit = True
else:
print("Invalid choice")
else:
print("Invalid account number")
1. Techniques:
a. Check account number and password (iteration and validation, selection, input, output)
b. Display menu and make a selection (output, input and selection)
c. Perform actions selected (use of arrays and procedures with parameters)
2. Data Structures:
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 11
Examiner Tips and Tricks
All criteria stated for the scenario have been covered by the use of appropriate programming techniques
The data structures used store all the data that is required by the scenario
All the data structures used have meaningful names
Solution logically performs all the tasks given in the scenario
(15 marks)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 12