ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
13 marks · Data types and structures
Using a programming language of your choice, define a suitable record data structure for the washing machine data above. The record data structure should be called feature. Using a programming language of your choice, declare the variable called machines which can store the details of the 80 washing machines. Your answer should use the record data structure created in part (i). Customers often ask questions about the washing machines. For example: ‘How much is the cheapest washing machine that can do a wash load of 11 kg or more and a spin speed of 1500 rpm or more?’ The top-level design for the algorithm to answer this question is shown below: 1. Read data from text file into data structure. 2. Ask user to enter the smallest wash load and the slowest spin speed required. 3. Find the price of the cheapest washing machine(s) if there is one that meets the entered criteria. 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’. Complete the table below to show the missing data flow for steps 3 and 4. Step IN/OUT Data flow 1 IN OUT machines() 2 IN OUT smallestWash, slowestSpin 3 IN OUT cheapestPrice, found 4 IN OUT Step 3 finds the price of the cheapest washing machine(s) that meets the entered criteria. If there is not a washing machine that meets the criteria then found is set to false. Using a programming language of your choice, write the code for step 3. Your answer should use the data structure created in part (a). 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 speed (rpm) Price (£) Number in stock Doolton D120 11 1400 389.99 34 Hisky H873 10 1400 289.99 42 Aarch A423 10 1500 279.00 3 Doolton D232 12 1500 279.29 22 Aarch A189 12 1600 349.99 12 Doolton D387 10 1500 299.00 36 … … … … … … A program is designed to help customers decide which washing machine to buy.
Award 1 mark for each bullet. • Record structure with name feature • Six fields specified SQARL RECORD feature IS (STRING brand, STRING refNo, INTEGER maxWashLoad, INTEGER spinSpeed, REAL price, INTEGER numberInStock) Award 1 mark for each bullet. • Array structure and size (named machines) • Using feature data type SQARL DECLARE machines AS ARRAY OF feature INITIALLY[]*80 Python machines = [feature() for x in range(80)] parameters to initialise record may be passed in for example feature(‘’,’’...) VB Dim machines(79/80) as feature Award 1 mark for each bullet: • STEP 3 IN: smallestWash, slowestSpin, machines[ ] • STEP 4 IN: cheapestPrice, found Award 1 mark for each bullet. • Suitable initialisation of cheapestPrice • [ ].washLoad >= smallestWash AND [ ].spinSpeed >= slowestSpin • price < cheapestPrice • Assign cheapest • Found set to false, changed to true when all conditions met • Use of array of records, machines • with matching fields from a(i) (dot notation) Candidates may initialise cheapestPosition If an iterator is used eg FOR EACH washer FROM machines DO an index for the array is not required, for example washer.spinSpeed 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 AND machines[index].price < cheapestPrice THEN SET cheapestPrice TO machines[index].price SET found TO TRUE END IF END FOR
Previous question: Higher Computing Science 2023 Question 10