TK Study

Software Engineering › Notes › Master model answers: code, SQL, pseudocode, diagrams and tables

Master model answers: code, SQL, pseudocode, diagrams and tables

hsc2025-q19 (3 marks, Python)

Topic: Developing secure code (Python). Source: NESA 2025 HSC exam marking guidelines.

Question

In an organisation, temporary passwords are automatically generated for new user accounts. Each password is created from the first three letters of the username followed by '123'. For example, the username 'NESA' will have the password 'NES123'. When a user logs in for the first time, they are asked for their username and password. They receive a welcome message or an error message, depending on whether the password entered follows the rules of new user accounts. Write a Python program that asks a new user for their username and password, and then checks whether the password rule has been followed. (3 marks)

Marking criteria (NESA)

3: Correct code for the problem. 2: Partially correct code that includes a correct selection structure OR password creation. 1: Some understanding of the scenario and Python.

Model answer (NESA sample answer / MG)

uName = input('What is your username?')
password = input('What is your password?')
passwordP1 = uName[:3]
passwordP1= passwordP1 + '123'
if passwordP1 == password:
      print ('Welcome!')
else:
      print ('Incorrect password entered')

Note: Marker feedback: process string inputs; use a selection structure; code must execute in the environment; use correct indentation; call functions in the main program after defining them.

hsc2025-q26 (5 marks, Python)

Topic: Design, construct and implement a solution (Python). Source: NESA 2025 HSC exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Exact question wording is not published as a paper (online exam). Task as shown by the NESA marking guidelines/mapping grid: Python program: generate 15 unique random numbers from 1 to 25 and print a 5 by 5 grid, with an X in each grid position whose number is in the list and a blank otherwise. Task inferred from the MG sample answer; the exact stem is not published as text]

Marking criteria (NESA)

5: Correct Python program that creates a list of unique randomly generated numbers; processes the list correctly; uses selection and looping structures; provides correctly formatted output; uses inbuilt Python functions. 4: Substantially correct, most requirements. 3: Some requirements. 2: One requirement. 1: Some understanding of the problem.

Model answer (NESA sample answer / MG)

import random

randList = []
for x in range(15):
   nextInt = random.randint(1,25)
   while nextInt in randList:
      nextInt = random.randint(1,25)
   randList.append(nextInt)

pos = 0
while pos < 25:
  if pos in randList:
      print ("| X", end=" ")
  else:
      print ("| ", end=" ")
  pos = pos + 1
  if (pos % 5 == 0):
      print("| \n")

Note: FLAG: the NESA sample tests pos (0 to 24) against numbers 1 to 25, so it is off by one (25 is never marked, 0 never appears). Safer: test pos + 1 in randList. Marker feedback: replicate the grid; use the random library; use selection and looping to access the list; include a method of checking the number of values; use meaningful variable names and constants; avoid overly complex structures such as nested IF loops.

fam-q13 (6 marks, Python)

Topic: Python: lists, loops, selection. Source: NESA Familiarisation exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: Python program to display a player's scores and points per round from a list of 10 scores, with bonus points when a round scores 5 (add the next round's score) and a final-round rule (10 points), then the total]

Marking criteria (NESA)

6: Substantially correct solution with ALL of: looping correctly; referring to the contents of the data structure correctly; displaying the player's scores and corresponding points as shown; calculating the total points; taking bonus points into account; handling the final round correctly. 5: Most features. 3-4: Some features. 2: One feature. 1: Some understanding.

Model answer (NESA sample answer / MG)

# Input code
scores = [3,5,5,2,1,4,0,1,4,5]

# Display the scores and points

# Header row
print("Round\tScore\tPoints")
totalPoints = 0

# Calculate the points and print
for i in range(len(scores)):
    roundNumber = i + 1
    score = scores[i]
    points = score

    # Check if any bonuses apply and NOT the final round
    if points == 5 and i != 9:
        # Add the points from the next round as bonus points
        points += scores[i + 1]

    # Check if the final round bonus applies
    if points == 5 and i == 9:
        # Give the bonus points of 10
        points = 10

    # Add to the total points tally
    totalPoints += points

    # Print the results
    print(str(roundNumber) + "\t" + str(score) + "\t" + str(points))

print("\nTOTAL POINTS: " + str(totalPoints))

Note: The full stem is not available; the requirements are inferred from the MG criteria and sample answer. FLAG: in the MG text the comment and the print("Round...") are run together on one line (a typesetting error); they are shown here on separate lines.

sample-q18b (3 marks, Python (function))

Topic: Developing secure code (Python input validation). Source: NESA Sample Exam marking guidelines.

Question

(b) Write a function in Python that will check whether a username satisfies the rules (the four username rules in 18a). (3 marks)

Marking criteria (NESA)

3: Correct function in Python to check whether a username satisfies the rules. 2: Partially correct function. 1: Some understanding of the problem and Python.

Model answer (NESA sample answer / MG)

def validate_username(username):
     valid = True

     # length check
     if len(username) < 8:
          valid = False
     elif (not username[0].isupper()):
          valid = False
     elif (not username[-2].islower()):
          valid = False
     elif (not username[-1].isdigit()):
          valid = False

     return valid

Note: Remember to call the function in the main program after defining it, e.g. print(validate_username(input('Username: '))).

fam-q9b (3 marks, Python (function))

Topic: Developing secure code (Python input validation). Source: NESA Familiarisation exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: a Python function that checks whether a username satisfies given rules (stem not available)]

Marking criteria (NESA)

3: Correct function in Python that checks whether a username satisfies the rules. 2: Partially correct function. 1: Some understanding of the problem and Python.

Model answer (NESA sample answer / MG)

def validateUsername(username):

      # Length check
      if len(username) > 8:
          return False

      # Alpha character only check
      elif username.isalpha() == False:
          return False

      # < character check
      elif "<" in username:
          return False

      # If we reach here then the username meets the requirements
      return True

Note: Answers may include print statements to test the code, e.g. print(validateUsername("test")). The rules implied by the sample: no more than 8 characters, letters only, no '<'.

sample-q21b (5 marks, Python (subroutines, 2D list))

Topic: Python: subroutines, lists, loops. Source: NESA Sample Exam marking guidelines.

Question

At a school each student studies five subjects; five periods each day; each period is a different subject; the subject shifts to a different period each day so each subject appears in all five periods during the week. Example: Monday P1 English, P2 Software, P3 Drama, P4 Science, P5 Sport; Tuesday P1 Sport, P2 English, ... Write a Python program (using subroutines) that prints the timetable as: Monday / Period 1: English / Period 2: Software ... for all five days. Start with: subjects = ["English", "Software", "Drama", "Science", "Sport"]. Different students may study different subjects; the program will be used by changing the first line only. (5 marks)

Marking criteria (NESA)

5: Substantially correct Python program that places each subject in the correct period; displays all 5 days; provides appropriate subroutines; programmatically builds the timetable. 4: Most requirements. 3: Some requirements. 2: One requirement. 1: Some understanding.

Model answer (NESA sample answer / MG)

subjects = ["English", "Software", "Drama", "Science", "Art"]
NUM_DAYS = 5
NUM_PERIODS = 5
DAYS_OF_WEEK = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

def create_timetable(subjects):
    timetable = []
    for day in range(NUM_DAYS):
        periods = []
        for period in range(NUM_PERIODS):
            periods.append(subjects[(period - day) % NUM_PERIODS])
        timetable.append(periods)
    return timetable

def print_timetable(timetable):
    print()
    for day in range(NUM_DAYS):
        print(f"{DAYS_OF_WEEK[day]}")
        for period in range(NUM_PERIODS):
            print(f"\tPeriod {period+1}: {timetable[day][period]}")
        print()


timetable = create_timetable(subjects)
print_timetable(timetable)

Note: The key is the modulus: subjects[(period - day) % 5]. (The MG sample lists 'Art' where the question has 'Sport' - the program is meant to work with any five subjects.)

hsc2025-q21 (4 marks, SQL)

Topic: SQL queries. Source: NESA 2025 HSC exam marking guidelines.

Question

Below is the Issues table for a technical support company. FixTime, in minutes, is the time taken to complete each job. [table image not extractable: columns include JobID, Category, Status, FixTime] Construct a SQL query that displays: the number of pending software jobs; the number of pending hardware jobs; the number of escalated software jobs; the number of escalated hardware jobs. List the results in order from the highest to lowest, based on the number of jobs. (4 marks)

Marking criteria (NESA)

4: Correct SQL query that extracts 'Pending' and 'Escalated' jobs for the 'Software' and 'Hardware' categories, counts the jobs for each status in each category, and outputs results in descending order. 3: Addresses most requirements. 2: Some understanding of the problem. 1: Some understanding of SQL or the problem.

Model answer (NESA sample answer / MG)

SELECT Category, Status, COUNT(JobID) AS Jobs
FROM Issues
WHERE (Status = 'Pending' OR Status = 'Escalated')
GROUP BY Status, Category
ORDER BY Jobs DESC

Note: Note: the sample does not filter Category to Software/Hardware (the table is assumed to have only those two). Adding AND (Category = 'Software' OR Category = 'Hardware') is safe. Marker feedback: query must run; quotation marks around data being searched; use OR/AND in WHERE; correct GROUP BY and ORDER BY fields.

sample-q17 (3 marks, SQL)

Topic: SQL (join, filter, order). Source: NESA Sample Exam marking guidelines.

Question

A shop uses an online database with a Products table (ProductID, Name, Price, Mass, Producer, Quantity, SupplierID) and a Suppliers table (SupplierID, Name). The prices are in dollars and the masses are in grams. The shop wants to identify all the products with a mass of at least 50 grams that are produced by Yumtreats. Write an SQL query to display the product names and supplier names, in descending order by product name. (3 marks)

Marking criteria (NESA)

3: Correct SQL query. 2: Addresses some of the requirements. 1: Some understanding of SQL.

Model answer (NESA sample answer / MG)

SELECT Products.Name AS 'Product', Suppliers.Name AS 'Supplier'
FROM Products, Suppliers
WHERE Products.SupplierID = Suppliers.SupplierID
    AND Products.Producer = 'Yumtreats'
    AND Products.Mass >= 50
ORDER BY Products.Name DESC

Note: An INNER JOIN ... ON equivalent is equally valid. Quote text values. Both tables have a column called Name, so qualify them (Table.Name).

sample-q22a (2 marks, SQL (fill the blanks))

Topic: SQL (GROUP BY). Source: NESA Sample Exam marking guidelines.

Question

A table Students(StudentID, FirstName, Surname, Attended, Level) tracks students at a coding club (12 rows; levels Beginner, Intermediate, Expert). Complete the SQL query to generate the number of students at each level: SELECT Level, ??? FROM Students ??? BY Level;

Marking criteria (NESA)

2: Correctly completes the SQL query. 1: Correctly selects at least TWO correct options.

Model answer (REASONED, not copied: the official answer was an image)

SELECT Level, COUNT(StudentID)
FROM Students
GROUP BY Level;

Note: REASONED (not copied): the MG answer is an image/table that could not be extracted. The dropdown option list is not extractable. COUNT() is also valid.*

fam-q12b (3 marks, SQL (three tables, aliases))

Topic: SQL (joins, AS). Source: NESA Familiarisation exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: write a SQL query over Customers, Products and Orders showing customer, product and quantity with renamed columns, ordered by OrderID]

Marking criteria (NESA)

3: Correct SQL query. 2: Substantially correct query with at least TWO of: renaming the columns; selecting the three tables; joining the tables. 1: Some understanding of renaming the columns or joining the tables.

Model answer (NESA sample answer / MG)

SELECT Customers.CustName as 'Customer', Products.ProductName as 'Product',
Orders.OrderQuantity as 'Quantity'
FROM Products, Customers, Orders
WHERE Orders.ProductID = Products.ProductID
AND Orders.CustID = Customers.CustID
ORDER BY Orders.OrderID ASC

sample-q5 (1 marks, drag and drop (match))

Topic: Implementation methods. Source: NESA Sample Exam marking guidelines.

Question

New systems can be implemented in a number of different ways. Match the implementation methods (Direct, Parallel, Phased, Pilot) to: (i) The new system runs immediately with no delay. (ii) The new system gradually replaces the old system. (iii) The new system and the old system run at the same time. (iv) The new system is trialled with a small group of users and then implemented entirely when ready.

Marking criteria (NESA)

1: Correctly matches the implementation methods.

Model answer (REASONED, not copied: the official answer was an image)

(i) Direct. (ii) Phased. (iii) Parallel. (iv) Pilot.

Note: REASONED (not copied): the MG answer is an image/table that could not be extracted. Standard definitions from the course.

sample-q9 (2 marks, drag into order (algorithm))

Topic: Algorithm design (guessing game). Source: NESA Sample Exam marking guidelines.

Question

Place the steps of a number guessing game algorithm in the correct order. BEGIN GuessingGame; Set guess = -1; [steps]; END GuessingGame. Steps: Display "Guess a number between 0 and 100:"; Display "Well Done"; Set number = random integer between 0 and 100; WHILE guess <> number; Get guess; ENDWHILE.

Marking criteria (NESA)

2: Correctly orders the steps. 1: Correctly orders the WHILE and ENDWHILE steps.

Model answer (REASONED, not copied: the official answer was an image)

Set number = random integer between 0 and 100
WHILE guess <> number
   Display "Guess a number between 0 and 100:"
   Get guess
ENDWHILE
Display "Well Done"

Note: REASONED (not copied): the MG answer is an image/table that could not be extracted. The prompt/Get guess pair must be inside the loop; 'Well Done' after ENDWHILE.

hsc2025-q2 (1 marks, dropdown (fill in blanks))

Topic: Software development approaches. Source: NESA 2025 HSC exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Exact question wording is not published as a paper (online exam). Task as shown by the NESA marking guidelines/mapping grid: software development approaches, two dropdowns]

Marking criteria (NESA)

1: Identifies the correct item from each dropdown.

Model answer (NESA sample answer / MG)

Dropdown 1: Waterfall. Dropdown 2: Agile.

hsc2025-q9 (1 marks, matching table (tick which approach))

Topic: ORM and SQL. Source: NESA 2025 HSC exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

Match each characteristic to ORM, SQL, or both: (1) Code is focused on object manipulation; (2) Tables can be joined to enhance searching; (3) Programmers can choose the language used to access the database. [Characteristics as printed in the MG answer table; the question's introductory wording is not published.]

Marking criteria (NESA)

1: Correctly matches each characteristic to the appropriate approach.

Model answer (NESA sample answer / MG)

(1) ORM only. (2) Both ORM and SQL. (3) ORM only.

Note: Read from the MG table layout: row 2 has two ticks; rows 1 and 3 have one tick in the ORM column.

hsc2025-q17 (3 marks, pseudocode)

Topic: Algorithm design. Source: NESA 2025 HSC exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Exact question wording is not published as a paper (online exam). Task as shown by the NESA marking guidelines/mapping grid: pseudocode RiskRating: the sample answer sums an array Risks of 10 values, then sets Rating to High if Total > 35, Low if Total < 20, otherwise Medium, and displays it]

Marking criteria (NESA)

3: Substantially correct pseudocode algorithm. 2: Addresses some aspects of the problem. 1: Some understanding of the problem or pseudocode.

Model answer (NESA sample answer / MG)

BEGIN RiskRating
  Total = 0
  index = 0
  REPEAT
    Total = Total + Risks[index]
    index = index + 1
  UNTIL index = 10
  IF Total > 35 THEN
    Rating = "High"
  ELSE
    IF Total < 20 THEN
      Rating = "Low"
    ELSE
      Rating = "Medium"
    ENDIF
  ENDIF
  Display Rating
END RiskRating
(NESA also accepts a CASEWHERE version: CASEWHERE Total is  > 35: Rating = "High"  < 20: Rating = "Low"  OTHERWISE: Rating = "Medium"  END CASE; and an IF / ELSEIF / ELSE version.)

Note: Marker feedback: use pseudocode control structures accurately; iterate an array and sum it; apply relational operators correctly; use the stimulus to choose the right structures.

sample-q14 (3 marks, pseudocode)

Topic: Algorithm design (subroutines). Source: NESA Sample Exam marking guidelines.

Question

PseudoPizza sells custom-designed pizzas. The price of a small pizza is $10. Added costs: Medium size $2; Large size $4; each topping $1.50. An algorithm is needed to calculate the cost of pizzas ordered for a customer. The algorithm should calculate and display: the cost of each pizza; the total cost of the order. Write the algorithm using pseudocode. Include at least one subroutine in your answer. You may assume that all inputs are valid. (3 marks)

Marking criteria (NESA)

3: Substantially correct pseudocode that includes at least ONE subroutine. 2: Addresses some of the requirements. 1: Some understanding of the problem.

Model answer (NESA sample answer / MG)

BEGIN main
     Get num_pizzas
     total_cost = 0
     FOR i = 1 TO num_pizzas
           Get pizza_size
           Get num_toppings
           cost_per_pizza = calculate_pizza_cost(pizza_size, num_toppings)
           DISPLAY cost_per_pizza
           total_cost = total_cost + cost_per_pizza
     NEXT i
     DISPLAY total_cost
END main

BEGIN calculate_pizza_cost(size, num_toppings)
     base_price = 10
     topping_price = 1.5
     IF size = "Medium" THEN
           base_price = base_price + 2
     ELSEIF size = "Large" THEN
           base_price = base_price + 4
     ENDIF
     pizza_cost = base_price + num_toppings * topping_price
     RETURN pizza_cost
END calculate_pizza_cost

fam-q8 (3 marks, pseudocode (fix algorithm))

Topic: Algorithm design (linear search). Source: NESA Familiarisation exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: modify a search algorithm so it achieves its intended purpose (find SearchItem in ItemArray and display its position, otherwise 'Not found')]

Marking criteria (NESA)

3: Correctly modifies the algorithm to achieve its intended purpose. 2: Corrects some mistakes. 1: Some understanding of the problem.

Model answer (NESA sample answer / MG)

BEGIN Search (SearchItem)
    Set LastIndex to the number of elements in ItemArray
    Found = FALSE
    Index = 1
    WHILE Found = FALSE AND Index < LastIndex + 1
         IF ItemArray(Index) = SearchItem THEN
               Found = TRUE
         ENDIF
         Index = Index + 1
    ENDWHILE
    IF Found = TRUE THEN
         Display 'Position', Index - 1
    ELSE
         Display 'Not found'
    ENDIF
END Search

Note: The original (buggy) algorithm is not available. Note the 'Index - 1' because Index is incremented after the item is found.

fam-q12a (2 marks, table (SQL output))

Topic: SQL. Source: NESA Familiarisation exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: give the output of an SQL query on a product table, including correct ordering of rows]

Marking criteria (NESA)

2: Correct output for the SQL query, including the correct ordering of the rows. 1: Some relevant information.

Model answer (NESA sample answer / MG)

ProductName / ProductPrice: Discovery 1 & 2 (DVD) 26.98; The Plant (DVD) 28.00

Note: The query is not available; the output shown is the MG sample answer.

sample-q8 (2 marks, table (classify SAST/DAST))

Topic: SAST and DAST. Source: NESA Sample Exam marking guidelines.

Question

The strategies below can be used to test the security of a web application that contains a database. Classify each as EITHER SAST OR DAST: (1) Simulate attacks on the web application; (2) Check the way SQL queries are constructed; (3) Test the database's web interface for vulnerabilities; (4) Test the web application used to interact with the database when it is running; (5) Analyse the code for connecting to the database to identify security vulnerabilities.

Marking criteria (NESA)

2: Correctly classifies all the strategies. 1: Correctly classifies THREE strategies, which must include ONE SAST and ONE DAST.

Model answer (REASONED, not copied: the official answer was an image)

SAST: (2) and (5). DAST: (1), (3) and (4).

Note: REASONED (not copied): the MG answer is an image/table that could not be extracted. SAST = static, analyses code without running it; DAST = dynamic, tests the running application (simulated attacks, probing interfaces).

sample-q11 (3 marks, table (test data))

Topic: Testing (test data). Source: NESA Sample Exam marking guidelines.

Question

Algorithm: BEGIN responsiveScreen / Get ScreenSize / IF ScreenSize >= 1024 THEN Viewport = 'Desktop' / ELSEIF ScreenSize >= 768 THEN Viewport = 'Tablet' / ELSE Viewport = 'Phone' / ENDIF / Display "Display set to ", Viewport / END. Provide a set of test data that will thoroughly test the algorithm. Include expected outputs and reasons for inclusion. (Table: Test data (ScreenSize), Expected output (Viewport), Reason for inclusion; 3 rows shown.)

Marking criteria (NESA)

3: Test data that thoroughly tests the algorithm, with expected outputs and reasons. 2: Tests most of the boundaries and paths, with relevant outputs and reasons. 1: Some relevant information.

Model answer (NESA sample answer / MG)

1024 -> Desktop (boundary check). 768 -> Tablet (boundary check). 100 -> Phone (below lowest screen size check). 850 -> Tablet (between Tablet and Desktop). 2000 -> Desktop (above highest screen size check).

Note: Good extras: 1023 (just below desktop boundary) and 767 (just below tablet boundary). Test boundary values, both sides of each boundary, and one value for each path.

fam-q5 (3 marks, table (test data))

Topic: Testing (test data). Source: NESA Familiarisation exam marking guidelines.

Question (NESA did not publish the exact wording; this is reconstructed from the marking guideline)

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: test data for an algorithm that converts a Mark to a Grade (H, P, N) using the boundaries 80 and 50, per the sample answer]

Marking criteria (NESA)

3: Test data that thoroughly tests the algorithm, with expected outputs and reasons for inclusion. 2: Tests most boundaries and/or paths, with most expected outputs and reasons. 1: Some relevant information.

Model answer (NESA sample answer / MG)

85 -> H (testing greater than 80). 80 -> H (boundary value 80). 60 -> P (between 50 and 80). 50 -> P (boundary value 50). 45 -> N (testing 'otherwise', below 50).