0% found this document useful (0 votes)
11 views12 pages

Arrays fgq4Smn7Hgn78jrw

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views12 pages

Arrays fgq4Smn7Hgn78jrw

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

IGCSE Cambridge (CIE) Computer Science 36 mins 5 questions

Exam Questions

Arrays
Arrays

Easy (1 question) /1 Scan here to return to the course


or visit savemyexams.com
Medium (1 question) /3

Hard (3 questions) /32

Total Marks /36

© 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

The correct answer is A

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

C is incorrect as a function is a sub program that returns a value

D is incorrect as a variable is an identifier that can change 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.

Include an example of an array declaration.

Answer

A one-dimensional array is described as:

Any two of the following:

a list / one column of items [1 mark]


… of the same data type [1 mark]
… stored under a single identifier [1 mark]

… with a single index to identify each element [1 mark]


One mark for an example of a declaration

example e.g. DECLARE MyArray[1:10] OF INTEGER [1 mark]

(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

Indexing could be used by:

using a counter to index the array [1 mark]


… so that the same code can be repeatedly used to check every element OR every element can be checked in a loop [1
mark]

(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.

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

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

# Declare and initialise required data structures


days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
readings = [[0.0 for _ in range(24)] for _ in range(7)]
average_temp = [0.0 for _ in range(7)]

# Variables for calculations

© 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

# Input temperatures inside nested loop


for week_loop in range(7):
total_day_temp = 0.0
for day_loop in range(24):
# Prompt for temperature input
in_temp = float(input(f"Enter temperature {day_loop + 1} for {days[week_loop]}: "))

# Validation for temperature between -20 and +50 inclusive


while in_temp < -20.0 or in_temp > 50.0:
print("Your temperature must be between -20.0 and +50.0 inclusive. Please try again")
in_temp = float(input(f"Enter temperature {day_loop + 1} for {days[week_loop]}: "))

# Store validated temperature


readings[week_loop][day_loop] = in_temp

# Totalling temperatures during the day


total_day_temp += round(in_temp, 1)

# Calculate average temperature for the day


average_temp[week_loop] = round(total_day_temp / 24, 1)

# Calculate the average temperature for the week


for week_loop in range(7):
total_week_temp += average_temp[week_loop]

average_week_temp = round(total_week_temp / 7, 1)

# Outputs in Celsius and Fahrenheit


for week_loop in range(7):
average_temp_fahrenheit = round((average_temp[week_loop] * 9 / 5) + 32, 1)
print(f"The average temperature on {days[week_loop]} was {average_temp[week_loop]} Celsius and {average_temp_fahrenheit} Fahrenheit")

# Output the average temperature for the entire week


average_week_temp_fahrenheit = round((average_week_temp * 9 / 5) + 32, 1)
print(f"The average temperature for the week was {average_week_temp} Celsius and {average_week_temp_fahrenheit} Fahrenheit")

Mark Scheme and Guidance


You must include the following in your solution to achieve a maximum score:

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

a. Arrays or lists: Days[], Readings[], AverageTemp[]


b. Variables: WeekLoop, DayLoop, InTemp, TotalDayTemp, TotalWeekTemp, AverageWeekTemp

© 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.

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

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

PROCEDURE WithDrawal(AccID : INTEGER)


DECLARE Amount : REAL // local variable
REPEAT
OUTPUT "Please enter amount to withdraw "
INPUT Amount
IF Amount > AccDetails[AccID,3]
THEN
OUTPUT "Amount greater than withdrawal limit"
ENDIF
IF Amount > AccDetails[AccID,2] + AccDetails[AccID,1]
THEN
OUTPUT "Amount greater than cash available"
ENDIF
IF Amount <= AccDetails[AccID,3] AND Amount < AccDetails[AccID,2] + AccDetails[AccID,1]
THEN
AccDetails[AccID,1] AccDetails[AccID,1] - Amount
ENDIF
UNTIL Amount<= AccDetails[AccID,3] AND Amount > AccDetails[AccID,2] + AccDetails[AccID,1] AND Amount > 0
ENDPROCEDURE

PROCEDURE Deposit(AccID : INTEGER)


DECLARE Amount : REAL // local variable
REPEAT
OUTPUT "Please enter a positive amount to deposit "
INPUT Amount
UNTIL Amount >0 AccDetails[AccID,1] AccDetails[AccID,1] + Amount
ENDPROCEDURE
// Declarations of global variables for information – not required in candidate responses
DECLARE AccountNumber, Choice : INTEGER
DECLARE Valid, Exit : BOOLEAN

OUTPUT "Please enter your account number "


INPUT AccountNumber
CheckDetails(AccountNumber)

© 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

# Declare global variables for account details


Account = {
1: ["JohnDoe", "password123"], # Example account with name and password
2: ["JaneSmith", "mypassword"], # Add more as needed
}

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

# Procedure to check account details


def CheckDetails(AccID):
global Valid # Ensure we can modify the global Valid variable
if AccID not in Account:
print("Invalid Account Number")
else:
Name = input("Please Enter Name: ")
Password = input("Please Enter Password: ")
if Name != Account[AccID][0] or Password != Account[AccID][1]:
print("Invalid name or password")
else:
Valid = True

# Procedure to display balance


def Balance(AccID):
print(f"Your balance is {AccDetails[AccID][0]}")

# Procedure for withdrawal


def Withdrawal(AccID):
while True:
Amount = float(input("Please enter amount to withdraw: "))
if Amount > AccDetails[AccID][2]:
print("Amount greater than withdrawal limit")
elif Amount > AccDetails[AccID][0] + AccDetails[AccID][1]:

© 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

# Procedure for deposit


def Deposit(AccID):
while True:
Amount = float(input("Please enter a positive amount to deposit: "))
if Amount > 0:
AccDetails[AccID][0] += Amount
print(f"Deposit 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")

Mark Scheme and Guidance


You must include the following in your solution to achieve a maximum score:

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:

required names shown underlined must be used as given in the scenario

a. Arrays or lists: Account, AccDetails


b. Variables: Size, AccountNumber

© 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy