SQA Higher Computing Science 2025 Assignment Practice

Orders Task Simulation

Task 1: Software Design and Development

Problem Description

A fast-food outlet uses an app to allow users to order food online. The data collected by the app is stored in a text file. The owner of the fast-food outlet wants a program to analyse and use this data.

Purpose

The program should:

The text file stores:

The data from the text file will be read into an array of records.

The program will display the total number of orders delivered and the total number of orders collected to date.

A month will be entered into the program to find the first customer to give a 5-star rating for that month. This customer will win a free meal. Details of the winning customer will be written to a text file called ‘winningCustomer.txt’. If there is no winning customer, a suitable message will be written to the file.

Assumptions

A text file ‘orders.txt’ is used when the program is being created. This file contains data for the 505 orders that were made in October, November and December 2024. A sample of this data is shown below.

Ord1,01-Oct-24,jacobjoseph@lukewarmmail.com,Delivery,14.45,4
Ord2,01-Oct-24,arthurian@geemail.com,Collection,34.24,1
Ord3,01-Oct-24,rebeccashearer@wahoo.co.uk,Collection,17.13,3
...
Ord505,31-Dec-24,buddy@lol.com,Collection,34.67,1

When the month October is entered, the expected output is shown below.

Enter the first three letters of the month to search: Oct
Total number of orders delivered to date: 290
Total number of orders collected to date: 215

The expected content of the file, ‘winningCustomer.txt’ is shown below.

Ord9,maxpower11@inlook.com,19.34

Task 1: software design and development (part A)

1a: Using the problem description, identify the missing functional requirements of the program. (3 marks)

Input(s)

  • Read the order number, date of order, customer email, delivery or collection option, order cost and customer star rating from file to an array of records.

Process(es)

Output(s)

  • Display the total number of orders delivered and the total number of orders collected.
  • Write details of the winning customer, or ‘no winner’ message, to a text file.

Task 1: software design and development (part B)

1b: The top-level design for the program, with missing data flow, is shown below. Complete the missing data flow in the table below. (2 marks)

# Step Description IN OUT
1 Read from file into array of records. orders(orderNum, date, email, option, cost, rating)
2 Find the position of the customer who gave the first 5-star rating in a given month. position
3 Write details of the winning customer, or ‘no winner’ message, to a text file.
orders(orderNum, date, email, option, cost, rating)
4 Display the total number of orders delivered and the total number of orders collected. orders(orderNum, date, email, option, cost, rating)

Task 1: software design and development (part C)

Your teacher or lecturer will provide you with a file called ‘orders.txt’.

The design of the program is shown below.

Program top-level design (pseudocode)

1 Read from file into array of records. OUT orders(orderNum,date,email,option,cost,rating)
2 Find the position of the customer who gave the first 5-star rating in a given month. IN orders(orderNum,date,email,option,cost,rating)
OUT position
3 Write details of the winning customer, or ‘no winner’ message, to a text file. IN orders(orderNum,date,email,option,cost,rating), position
4 Display the total number of orders delivered and the total number of orders collected. IN orders(orderNum,date,email,option,cost,rating)

Refinements

2.1 Set position to -1

2.2 Set index to 0

2.3 Ask user to enter month to search for

2.4 While position is -1 and index is less than the length of the array

2.5 If current month is equal to searched month and current rating is 5 then

2.6 Set position to index

2.7 End if

2.8 Add 1 to index

2.9 End while

2.10 Return position

3.1 Open new file ‘winningCustomer.txt’

3.2 If position is 0 or above then

3.3 Write winning order number, email and cost to ‘winningCustomer.txt’

3.4 Else

3.5 Write ‘No winner’ to ‘winningCustomer.txt’

3.6 End if

3.7 Close ‘winningCustomer.txt’

4.1 Call countOption function to return the number of orders delivered

4.2 Call countOption function to return the number of orders collected

4.3 Output the total number of orders delivered

4.4 Output the total number of orders collected

Task 1c: Implementation

1c: Using the problem description and design, implement the program in a language of your choice. (15 marks)

Your program should:

Print evidence of your:

orders.txt (Input File)
Format: orderNum,date,email,option,cost,rating
orders.py Python 3.11 (Pyodide)
class Order(): def __init__(self, orderNum, date, email, option, cost, rating): self.orderNum = orderNum #string self.date = date #string self.email = email #string self.option = option #string self.cost = float(cost) #real self.rating = int(rating) #int def readFromFile(): oArray = [] # Note: Paths changed to relative for web simulation entireFile = open("orders.txt", "r") linesArray = entireFile.read().splitlines() entireFile.close() for line in linesArray: lineSplit = line.split(",") currentOrder = Order(lineSplit[0], lineSplit[1], lineSplit[2], lineSplit[3], float(lineSplit[4]), int(lineSplit[5])) oArray.append(currentOrder) return oArray def findFirstFiveStarInMonth(oArray): # 2.1 Set position to -1 position = -1 # 2.2 Set index to 0 index = 0 # 2.3 Ask user to enter month to search for # Input will appear as a browser prompt month = str(input("Please enter the month you wish to find the first 5 Star review for (e.g. Oct): ")) # 2.4 While position is -1 and index is less than the length of the array while position == -1 and index < len(oArray): # print (oArray[index].date[3:6] == month) # 2.5 If current month is equal to searched month and current rating is 5 then if oArray[index].date[3:6] == month and oArray[index].rating == 5: # 2.6 Set position to index position = index # 2.7 End if # 2.8 Add 1 to index index += 1 # 2.9 End while # 2.10 Return position return position def createFile(oArray, pos): # 3.1 Open new file ‘winningCustomer.txt’ # Note: Paths changed to relative for web simulation entireFile = open("winningCustomer.txt", "w+") print (f"Winner found at index: {pos}") # 3.2 If position is 0 or above then if pos >=0: # 3.3 Write winning order number, email and cost to ‘winningCustomer.txt’ textToWrite = oArray[pos].orderNum + ", " + oArray[pos].email + ", " + str(oArray[pos].cost) entireFile.write(textToWrite) # 3.4 Else else: # 3.5 Write ‘No winner’ to ‘winningCustomer.txt’ entireFile.write("No winner") # 3.6 End if # 3.7 Close ‘winningCustomer.txt’ entireFile.close() def displayOrders(oArray): # 4.1 Call countOption function to return the number of orders delivered od = countOption(oArray, "Delivery") # 4.2 Call countOption function to return the number of orders collected oc = countOption(oArray, "Collection") # 4.3 Output the total number of orders delivered print (f"Deliveries: {od}") # 4.4 Output the total number of orders collected print (f"Collections: {oc}") def countOption(oArray, option): counter = 0 for order in oArray: if order.option == option: counter += 1 return counter # Main Execution try: #1. Read from file into array of records. ordersArray = readFromFile() #2. Find the position of the customer who gave the first 5-star rating in a given month. pos = findFirstFiveStarInMonth(ordersArray) #3. Write details of the winning customer, or ‘no winner’ message, to a text file. createFile(ordersArray, pos) #4. Display the total number of orders delivered and the total number of orders collected. displayOrders(ordersArray) except Exception as e: print(f"An error occurred: {e}")
Console Output

            
winningCustomer.txt (Generated Output)
File not created yet...

Task 1d: Trace Table

1d: The function ‘Find the position of the customer who gave the first 5-star rating in a given month’ is tested using the sample data below.

Ord165,31-Oct-24,scr83@lol.com,Collection,19.99,2
Ord166,31-Oct-24,itsjustjen@inlook.com,Delivery,24.00,4
Ord167,01-Nov-24,arthurian@geemail.com,Delivery,38.18,4
Ord168,01-Nov-24,thetribalchief@lol.com,Collection,12.49,5
Ord169,01-Nov-24,scr83@lol.com,Delivery,55.55,3
Ord170,01-Nov-24,duckguy@male.com,Collection,44.89,5

Complete the trace table below to show the values up to the end of the iteration of the conditional loop. (2 marks)

Month searched: Nov
orderNum position If current month is equal to searched month and current rating is 5
Ord165-1False
Ord166
Ord167
Ord168

Task 1e: Evaluation

1e: With reference to your own program code, evaluate the following.

Efficiency

The efficiency of your program with reference to the use of the ‘countOption’ function. (1 mark)

Maintainability

The maintainability of the first subprogram ‘Read from file into array of records’ if the file now contained data for a whole year from January 2025 to December 2025. Your answer should refer to data structures and loops. (2 marks)