Photo AI
Question 11
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
Step 1
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
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
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
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
Report Improved Results
Recommend to friends
Students Supported
Questions answered