Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Subject:
Topics:
Avg
score:
–
Topics
done:
0/32

15-mark scenario questions

Practise 16 exam-style questions on 15-mark scenario questions for Cambridge IGCSE Computer Science (Paper 2). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with an AI tutor on hand if you get stuck.

  • 16 questions
  • 15 marks each
  • Instant marking
  • No sign-up needed
16 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

15 marks

A weather station records the temperature, in °C, every hour for one week. The readings are stored in the 2D array Temperature[1:7, 1:24] of type REAL, where Temperature[2, 13] is the reading at hour 13 of day 2. The 1D array DayName[1:7] stores the names of the days, "Monday" to "Sunday". Both arrays have already been declared and contain the data.

Write a program that:
- finds, for each day, the highest and lowest temperature and calculates the average temperature
- outputs, for each day, the day name and its highest, lowest and average temperature, with the average rounded to one decimal place
- finds and outputs the name of the day with the greatest range of temperatures (highest minus lowest)
- counts and outputs the number of readings in the week that were below 0 °C
- then allows the user to input a day number, validated to be from 1 to 7, and outputs all 24 readings for that day with their hour numbers.

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

Model answer

// Temperature and DayName are already declared and contain the data
DECLARE Day, Hour, FreezingCount, WidestDay, Choice : INTEGER
DECLARE High, Low, Total, Range, WidestRange : REAL

FreezingCount ← 0
WidestRange ← -1.0
WidestDay ← 1

FOR Day ← 1 TO 7
    // Start each day with its first reading as both highest and lowest
    High ← Temperature[Day, 1]
    Low ← Temperature[Day, 1]
    Total ← 0.0
    FOR Hour ← 1 TO 24
        IF Temperature[Day, Hour] > High
          THEN
            High ← Temperature[Day, Hour]
        ENDIF
        IF Temperature[Day, Hour] < Low
          THEN
            Low ← Temperature[Day, Hour]
        ENDIF
        IF Temperature[Day, Hour] < 0
          THEN
            FreezingCount ← FreezingCount + 1
        ENDIF
        Total ← Total + Temperature[Day, Hour]
    NEXT Hour
    OUTPUT DayName[Day], ": highest ", High, ", lowest ", Low, ", average ", ROUND(Total / 24, 1)
    // Keep the day with the greatest range
    Range ← High - Low
    IF Range > WidestRange
      THEN
        WidestRange ← Range
        WidestDay ← Day
    ENDIF
NEXT Day
OUTPUT "Day with the greatest range: ", DayName[WidestDay]
OUTPUT "Number of readings below 0 °C: ", FreezingCount

// Show all the readings for a day chosen by the user
OUTPUT "Enter a day number (1 to 7)"
INPUT Choice
WHILE Choice < 1 OR Choice > 7 DO
    OUTPUT "The day number must be from 1 to 7. Enter it again"
    INPUT Choice
ENDWHILE
FOR Hour ← 1 TO 24
    OUTPUT "Hour ", Hour, ": ", Temperature[Choice, Hour], " °C"
NEXT Hour

Explanation

The highest and lowest are reset to the day's first reading at the start of each day, so every day is judged on its own readings; starting them at 0 would fail on a day that is entirely below or above 0 °C. The freezing count, by contrast, is set once before the loops because it covers the whole week. The final part validates the day number before it is used as an index, so the program can never try to read a row outside the array.

Mark scheme
  1. 1 mark

    MP1 declares the variables used with suitable data types

    Mark as Cambridge: credit each feature that is present and correctly used in a working solution; a solution in pseudocode, Python, Visual Basic or Java is accepted. max 15

  2. 1 mark

    MP2 initialises the freezing counter to 0 and the greatest range (e.g. to -1 or the first day's range) before the loops

  3. 1 mark

    MP3 outer loop for the 7 days

  4. 1 mark

    MP4 sets the highest and lowest to the first reading of the day (or suitable extreme values) and the total to 0 for each day

  5. 1 mark

    MP5 inner loop for the 24 hours, using Temperature[Day, Hour] with correct indexes

  6. 1 mark

    MP6 updates the highest when a reading is greater than it

  7. 1 mark

    MP7 updates the lowest when a reading is less than it

  8. 1 mark

    MP8 adds each reading to the day's total

  9. 1 mark

    MP9 counts readings below 0

  10. 1 mark

    MP10 calculates the average as total ÷ 24 after the inner loop, rounded to 1 decimal place

  11. 1 mark

    MP11 outputs the day name with its highest, lowest and average temperatures

  12. 1 mark

    MP12 calculates each day's range as highest - lowest

  13. 1 mark

    MP13 compares the range with the greatest so far and stores the day (index or name) of the greatest

  14. 1 mark

    MP14 outputs the name of the day with the greatest range and the freezing count after the loops

  15. 1 mark

    MP15 inputs a day number with a prompt

  16. 1 mark

    MP16 validates the day number is between 1 and 7, re-inputting with an error message until valid

  17. 1 mark

    MP17 loops through the 24 hours outputting each hour number and reading for the chosen day

  18. 1 mark

    MP18 comments explain the code and identifiers are meaningful

Question 2

15 marks

A shop sells 50 different items, numbered 1 to 50. The 1D arrays ItemName[1:50], Price[1:50] and Stock[1:50] store each item's name, price in £ and the number in stock; for example, Stock[7] is the number of item 7 in stock. The arrays have already been declared and contain the data.

Write a program that:
- repeatedly inputs the number of an item sold, until 0 is entered to finish; the item number must be from 0 to 50
- if the item is out of stock, outputs a message; otherwise inputs the quantity sold, which must be from 1 to the number in stock
- reduces the stock of the item by the quantity sold and outputs the item name and the cost of that sale
- keeps a running total of the value of all sales and counts the number of sales made
- when 0 is entered, outputs the total value of sales and the number of sales, then outputs the name and stock level of every item that now has fewer than 5 in stock.

Every input must be validated. You must use pseudocode or program code and add comments to explain how your code works. All inputs and outputs must contain suitable messages. Declare any variables you use.

Model answer

// ItemName, Price and Stock are already declared and contain the data
DECLARE Item, Quantity, NumSales : INTEGER
DECLARE Cost, SalesTotal : REAL

SalesTotal ← 0.0
NumSales ← 0

OUTPUT "Enter the item number sold (1 to 50), or 0 to finish"
INPUT Item
WHILE Item < 0 OR Item > 50 DO
    OUTPUT "Invalid item number: enter 1 to 50, or 0 to finish"
    INPUT Item
ENDWHILE

WHILE Item <> 0 DO
    IF Stock[Item] = 0
      THEN
        OUTPUT ItemName[Item], " is out of stock"
      ELSE
        OUTPUT "Enter the quantity sold (1 to ", Stock[Item], ")"
        INPUT Quantity
        // Cannot sell more than are in stock
        WHILE Quantity < 1 OR Quantity > Stock[Item] DO
            OUTPUT "Invalid quantity: enter 1 to ", Stock[Item]
            INPUT Quantity
        ENDWHILE
        Stock[Item] ← Stock[Item] - Quantity
        Cost ← Price[Item] * Quantity
        OUTPUT Quantity, " x ", ItemName[Item], " costs £", ROUND(Cost, 2)
        SalesTotal ← SalesTotal + Cost
        NumSales ← NumSales + 1
    ENDIF
    // Next item number
    OUTPUT "Enter the item number sold (1 to 50), or 0 to finish"
    INPUT Item
    WHILE Item < 0 OR Item > 50 DO
        OUTPUT "Invalid item number: enter 1 to 50, or 0 to finish"
        INPUT Item
    ENDWHILE
ENDWHILE

OUTPUT "Total value of sales: £", ROUND(SalesTotal, 2)
OUTPUT "Number of sales: ", NumSales
// Reorder list
OUTPUT "Items with fewer than 5 in stock:"
FOR Item ← 1 TO 50
    IF Stock[Item] < 5
      THEN
        OUTPUT ItemName[Item], ": ", Stock[Item], " left"
    ENDIF
NEXT Item

Explanation

The upper limit of the quantity check is the current value of Stock[Item], so the validation changes with each item and stock can never become negative. Checking for zero stock first matters: without it, the range 1 to 0 could never be satisfied and the validation loop would never end. The reorder list is produced after the sales loop, using the updated stock levels.

Mark scheme
  1. 1 mark

    MP1 declares the variables used with suitable data types

    Mark as Cambridge: credit each feature that is present and correctly used in a working solution; a solution in pseudocode, Python, Visual Basic or Java is accepted. max 15

  2. 1 mark

    MP2 initialises the sales total and the sales counter to 0

  3. 1 mark

    MP3 inputs an item number with a prompt

  4. 1 mark

    MP4 validates the item number is 0 to 50, re-inputting until valid

  5. 1 mark

    MP5 condition-controlled loop that ends when the item number is 0

  6. 1 mark

    MP6 checks whether Stock[Item] is 0 and outputs an out-of-stock message

  7. 1 mark

    MP7 otherwise inputs the quantity with a prompt

  8. 1 mark

    MP8 validates the quantity is at least 1 and no more than Stock[Item], re-inputting with an error message

  9. 1 mark

    MP9 subtracts the quantity from Stock[Item]

  10. 1 mark

    MP10 calculates the cost as Price[Item] × quantity

  11. 1 mark

    MP11 outputs the item name and cost of the sale

  12. 1 mark

    MP12 adds the cost to the running total and adds 1 to the number of sales

  13. 1 mark

    MP13 inputs the next item number (validated) inside the loop

  14. 1 mark

    MP14 outputs the total value of sales and the number of sales after the loop

  15. 1 mark

    MP15 loops through all 50 items after the sales have finished

  16. 1 mark

    MP16 outputs the name and stock level of each item with Stock < 5

  17. 1 mark

    MP17 comments explain the code and identifiers are meaningful

Question 3

15 marks

In a local election, five candidates stand and the votes are counted at eight polling stations. The candidates' names are stored in the 1D array CandidateName[1:5] and the votes in the 2D array Votes[1:5, 1:8], where Votes[2, 6] is the number of votes for candidate 2 at polling station 6. Both arrays have already been declared.

Write a program that:
- inputs the name of each candidate, which must not be empty
- inputs the number of votes for each candidate at each polling station, which must be from 0 to 5000, and stores it in Votes
- calculates each candidate's total number of votes and the total number of votes cast
- outputs each candidate's name, total votes and percentage of all the votes cast, rounded to one decimal place
- outputs the name of the winner (the candidate with the most votes) or, if two or more candidates share the highest total, the message "The result is a tie".

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 must declare any extra arrays and variables you use.

Model answer

// CandidateName and Votes are already declared
DECLARE CandidateTotal : ARRAY[1:5] OF INTEGER
DECLARE Candidate, Station, NumVotes, AllVotes, HighestVotes, Winner, NumAtHighest : INTEGER

AllVotes ← 0
FOR Candidate ← 1 TO 5
    OUTPUT "Enter the name of candidate ", Candidate
    INPUT CandidateName[Candidate]
    WHILE CandidateName[Candidate] = "" DO
        OUTPUT "The name must not be empty. Enter it again"
        INPUT CandidateName[Candidate]
    ENDWHILE
    CandidateTotal[Candidate] ← 0
    FOR Station ← 1 TO 8
        OUTPUT "Enter the votes for ", CandidateName[Candidate], " at polling station ", Station
        INPUT NumVotes
        WHILE NumVotes < 0 OR NumVotes > 5000 DO
            OUTPUT "Invalid: the votes must be from 0 to 5000. Enter them again"
            INPUT NumVotes
        ENDWHILE
        Votes[Candidate, Station] ← NumVotes
        CandidateTotal[Candidate] ← CandidateTotal[Candidate] + NumVotes
    NEXT Station
    AllVotes ← AllVotes + CandidateTotal[Candidate]
NEXT Candidate

// Percentages can only be worked out once every vote has been counted
HighestVotes ← -1
Winner ← 1
FOR Candidate ← 1 TO 5
    OUTPUT CandidateName[Candidate], ": ", CandidateTotal[Candidate], " votes (", ROUND(CandidateTotal[Candidate] / AllVotes * 100, 1), "%)"
    IF CandidateTotal[Candidate] > HighestVotes
      THEN
        HighestVotes ← CandidateTotal[Candidate]
        Winner ← Candidate
    ENDIF
NEXT Candidate

// Check for a tie at the top
NumAtHighest ← 0
FOR Candidate ← 1 TO 5
    IF CandidateTotal[Candidate] = HighestVotes
      THEN
        NumAtHighest ← NumAtHighest + 1
    ENDIF
NEXT Candidate
IF NumAtHighest > 1
  THEN
    OUTPUT "The result is a tie"
  ELSE
    OUTPUT "The winner is ", CandidateName[Winner]
ENDIF

Explanation

Each candidate's total is kept in an extra array so the percentages can be calculated afterwards: a percentage needs the total number of votes cast, which is not known until every vote has been input. Finding the highest total and then counting how many candidates have it is a simple way to detect a tie. The validation loops sit inside the nested loops, so every single value is checked before it is stored.

Mark scheme
  1. 1 mark

    MP1 declares an extra array (e.g. CandidateTotal[1:5]) and the variables used, with suitable data types

    Mark as Cambridge: credit each feature that is present and correctly used in a working solution; a solution in pseudocode, Python, Visual Basic or Java is accepted. max 15

  2. 1 mark

    MP2 initialises the total votes cast to 0 before the loops

  3. 1 mark

    MP3 outer loop for the 5 candidates, inputting each name with a prompt

  4. 1 mark

    MP4 presence check: re-inputs the name while it is empty

  5. 1 mark

    MP5 sets the candidate's total to 0 before the inner loop

  6. 1 mark

    MP6 inner loop for the 8 polling stations, inputting the votes with a prompt

  7. 1 mark

    MP7 validates the votes are 0 to 5000, re-inputting with an error message

  8. 1 mark

    MP8 stores each valid value in Votes[Candidate, Station]

  9. 1 mark

    MP9 adds the votes to the candidate's total

  10. 1 mark

    MP10 adds each candidate's votes to the total cast

  11. 1 mark

    MP11 calculates each percentage as candidate total ÷ total cast × 100 after all votes are entered

    Do not accept a percentage calculated before the total cast is complete.

  12. 1 mark

    MP12 rounds the percentage to 1 decimal place and outputs it with the name and total

  13. 1 mark

    MP13 finds the highest candidate total and stores which candidate has it

  14. 1 mark

    MP14 counts how many candidates have the highest total

  15. 1 mark

    MP15 outputs "The result is a tie" if more than one candidate has the highest total

  16. 1 mark

    MP16 otherwise outputs the name of the winner

  17. 1 mark

    MP17 comments explain the code and identifiers are meaningful

Question 4

15 marks

A restaurant has 8 dishes on its menu and 20 tables. The dish names are stored in the 1D array MenuItem[1:8] and their prices, in £, in the 1D array ItemPrice[1:8]; both already contain their data. The 1D array TableTotal[1:20] of type REAL has also been declared.

Write a program that:
- sets the total for every table to 0 at the start of the day
- processes orders until 0 is entered as the table number; each order starts with a table number from 1 to 20
- for each order, repeatedly inputs a dish number (1 to 8, or 0 to end the order) and a quantity (1 to 10), outputting the dish name, quantity and cost each time
- calculates the order total; if it is over £100.00, a 10% discount is taken off
- outputs the order total, adds it to that table's total in TableTotal and counts the number of orders
- at the end of the day, outputs the number of orders, the total takings and the number of the table that took the most money.

Every input must be validated. You must use pseudocode or program code and add comments to explain how your code works. All inputs and outputs must contain suitable messages. Declare any variables you use.

Model answer

// MenuItem and ItemPrice contain the data; TableTotal is declared
DECLARE Table, Dish, Quantity, NumOrders, BestTable : INTEGER
DECLARE Cost, OrderTotal, Takings : REAL

// Start of the day
FOR Table ← 1 TO 20
    TableTotal[Table] ← 0.0
NEXT Table
NumOrders ← 0

OUTPUT "Enter the table number (1 to 20), or 0 to finish for the day"
INPUT Table
WHILE Table < 0 OR Table > 20 DO
    OUTPUT "Invalid table number: enter 1 to 20, or 0"
    INPUT Table
ENDWHILE

WHILE Table <> 0 DO
    OrderTotal ← 0.0
    OUTPUT "Enter a dish number (1 to 8), or 0 to end the order"
    INPUT Dish
    WHILE Dish < 0 OR Dish > 8 DO
        OUTPUT "Invalid dish number: enter 1 to 8, or 0"
        INPUT Dish
    ENDWHILE
    // Add dishes to this order until 0 is entered
    WHILE Dish <> 0 DO
        OUTPUT "Enter the quantity (1 to 10)"
        INPUT Quantity
        WHILE Quantity < 1 OR Quantity > 10 DO
            OUTPUT "Invalid quantity: enter 1 to 10"
            INPUT Quantity
        ENDWHILE
        Cost ← ItemPrice[Dish] * Quantity
        OUTPUT Quantity, " x ", MenuItem[Dish], ": £", ROUND(Cost, 2)
        OrderTotal ← OrderTotal + Cost
        OUTPUT "Enter a dish number (1 to 8), or 0 to end the order"
        INPUT Dish
        WHILE Dish < 0 OR Dish > 8 DO
            OUTPUT "Invalid dish number: enter 1 to 8, or 0"
            INPUT Dish
        ENDWHILE
    ENDWHILE
    // 10% off orders over £100
    IF OrderTotal > 100.00
      THEN
        OrderTotal ← OrderTotal * 0.9
        OUTPUT "10% discount applied"
    ENDIF
    OUTPUT "Order total for table ", Table, ": £", ROUND(OrderTotal, 2)
    TableTotal[Table] ← TableTotal[Table] + OrderTotal
    NumOrders ← NumOrders + 1
    OUTPUT "Enter the table number (1 to 20), or 0 to finish for the day"
    INPUT Table
    WHILE Table < 0 OR Table > 20 DO
        OUTPUT "Invalid table number: enter 1 to 20, or 0"
        INPUT Table
    ENDWHILE
ENDWHILE

// End of the day
Takings ← 0.0
BestTable ← 1
FOR Table ← 1 TO 20
    Takings ← Takings + TableTotal[Table]
    IF TableTotal[Table] > TableTotal[BestTable]
      THEN
        BestTable ← Table
    ENDIF
NEXT Table
OUTPUT "Number of orders: ", NumOrders
OUTPUT "Total takings: £", ROUND(Takings, 2)
OUTPUT "Table that took the most money: ", BestTable

Explanation

Two condition-controlled loops are nested: the outer one processes orders until table 0, and the inner one adds dishes until dish 0. In both, the first value is input before the loop and the next one at the end of the loop body, so the rogue value 0 is never processed as real data. The discount is applied once to the whole order total after the inner loop, and the takings are found at the end by adding up TableTotal.

Mark scheme
  1. 1 mark

    MP1 declares the variables used with suitable data types

    Mark as Cambridge: credit each feature that is present and correctly used in a working solution; a solution in pseudocode, Python, Visual Basic or Java is accepted. max 15

  2. 1 mark

    MP2 loop that sets all 20 elements of TableTotal to 0, and the order counter set to 0

  3. 1 mark

    MP3 inputs a table number and validates it is 0 to 20, re-inputting until valid

  4. 1 mark

    MP4 outer condition-controlled loop that ends when the table number is 0

  5. 1 mark

    MP5 sets the order total to 0 at the start of each order

  6. 1 mark

    MP6 inputs a dish number and validates it is 0 to 8

  7. 1 mark

    MP7 inner loop that ends when the dish number is 0

  8. 1 mark

    MP8 inputs the quantity and validates it is 1 to 10, re-inputting with an error message

  9. 1 mark

    MP9 calculates the cost as ItemPrice[Dish] × quantity and outputs it with the dish name and quantity

  10. 1 mark

    MP10 adds the cost to the order total and inputs the next dish number (validated) inside the inner loop

  11. 1 mark

    MP11 applies a 10% discount (× 0.9) only when the order total is over 100

    Do not accept the discount applied to each dish.

  12. 1 mark

    MP12 outputs the order total

  13. 1 mark

    MP13 adds the order total to TableTotal[Table] and adds 1 to the number of orders

  14. 1 mark

    MP14 inputs the next table number (validated) at the end of the outer loop

  15. 1 mark

    MP15 after the loop, adds up all 20 table totals to give the takings

  16. 1 mark

    MP16 finds the table with the highest total, storing its number

  17. 1 mark

    MP17 outputs the number of orders, the total takings and the busiest table number

  18. 1 mark

    MP18 comments explain the code and identifiers are meaningful

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

AI Tutor Hints first, answers after you try

Hi! Stuck? Ask me for a hint and I’ll help you work it out. Once you’ve checked your answer I can explain exactly where the marks are.