Photo AI

A shop sells a range of 80 different washing machines - Scottish Highers Computing Science - Question 11 - 2023

Question icon

Question 11

A-shop-sells-a-range-of-80-different-washing-machines-Scottish Highers Computing Science-Question 11-2023.png

A shop sells a range of 80 different washing machines. Sample data about the washing machines is shown below: Brand RefNo Maximum wash load (kg) Spin s... show full transcript

Worked Solution & Example Answer:A shop sells a range of 80 different washing machines - Scottish Highers Computing Science - Question 11 - 2023

Step 1

Define a suitable record data structure for the washing machine data above.

96%

114 rated

Answer

The record data structure can be defined as follows:

RECORD Feature IS (
    STRING brand,
    STRING refNo,
    INTEGER maxWashLoad,
    INTEGER spinSpeed,
    REAL price,
    INTEGER numberInStock
)```
This structure includes fields for the washing machine's brand, reference number, maximum wash load, spin speed, price, and number in stock.

Step 2

Declare the variable called machines which can store the details of the 80 washing machines.

99%

104 rated

Answer

The variable can be declared as follows:

DECLARE machines AS ARRAY OF Feature INITIALIZE(80)```
This will create an array named `machines` capable of storing data for 80 washing machines, using the previously defined `Feature` record structure.

Step 3

3. Find the price of the cheapest washing machine(s) if there is one that meets the entered criteria.

96%

101 rated

Answer

To find the price for the cheapest washing machine, the following steps can be used:

SET cheapestPrice TO 999999
SET found TO FALSE

FOR index FROM 0 TO 79 DO
    IF machines[index].maxWashLoad >= smallestWash AND machines[index].spinSpeed >= slowestSpin THEN
        IF machines[index].price < cheapestPrice THEN
            SET cheapestPrice TO machines[index].price
            SET found TO TRUE
        END IF
    END IF
END FOR

Step 4

4. Display the price of the cheapest washing machine(s) that meets the entered criteria or a message stating 'No washing machine meets the criteria'.

98%

120 rated

Answer

To display the result, use the following code:

IF found THEN
    OUTPUT 'The price of the cheapest washing machine is: ' + cheapestPrice
ELSE
    OUTPUT 'No washing machine meets the criteria.'
END IF

Join the Scottish Highers students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;