A car manufacturer includes an event data recorder in their cars - Scottish Highers Computing Science - Question 11 - 2019
Question 11
A car manufacturer includes an event data recorder in their cars. This device begins recording when the car's sensors detect a sudden change in speed. The data captu... show full transcript
Worked Solution & Example Answer:A car manufacturer includes an event data recorder in their cars - Scottish Highers Computing Science - Question 11 - 2019
Step 1
State two boundaries for this task.
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The boundaries for the acceleration values, which must range between 0% and 100%.
The boundaries for the speed, which must have a minimum of 0 mph and the maximum dependent on the car's specifications.
Step 2
Using a programming language of your choice, define a suitable record data structure for the data above.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
class CarData:
def __init__(self):
self.speed = 0.0 # Speed in mph
self.accelerator = 0 # Accelerator percentage
self.brake = 0 # Brake percentage
self.seatbelt = False # Seatbelt status
Step 3
Using a programming language of your choice, define the variable which can store the details of the 200 readings.
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
readings = [CarData() for _ in range(200)]
Step 4
Using a recognised design technique, design an algorithm to find the maximum speed.
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Initialize max_speed to 0.
Loop through each reading in readings.
If reading.speed > max_speed, then:
Set max_speed to reading.speed.
End Loop.
Return max_speed.
Join the Scottish Highers students using SimpleStudy...