Average Speed Check Task 1 On many major





- Slides: 5
Average Speed Check Task 1 On many major roads average speed checks are in place. Two sensors are placed a known distance apart and vehicle number plate recognition is used to identify a vehicle and the time it enters the section of road being monitored. The time is recorded when the vehicle leaves the monitored section. By using the time taken to travel the known distance, the average speed of a vehicle can be calculated. Your task : Analyse the requirements for this system and design, develop, test and evaluate a program for calculating average speeds for a vehicle travelling through a section of road. Output a list of those vehicles exceeding the speed limit set for that section of road. 1. Write an introduction to the task and how you plan to solve it (task by task) 2. Produce a flowchart to ; a) accept a list of values (Reg, Distance, Time 1, Time 2, Speed limit) b) calculate the speed (speed = distance / time) c) Add each number place to the list d) Output the list on screen 3. Produce pseudocode for a) b) & create a set of test data and truth table 4. Write and annotate code for a) b) & c) ; Test your program code as you create it – annotate as you progress Test the final program with a set of test data
Start End Output list on screen Yes Enter Reg Enter Time 1 & Time 2 No Calculate time 2 – time 1 End of entries ? Enter Distance and Speed limit Calculate speed = distance / time Add to speed list Yes Is speed greater than limit ? No
Now create the psuedocode • Enter registration details • Enter Time record 1 How will you repeat this ? • Enter Time record 2 • [What else do you need to enter ? ] • Total time = Time 2 – Time 1 • If speed is greater than limit then; Add to speed- list the Registration and speed Otherwise, show message – not speeding Print speed-list
Test Data & truth table Athlete Time 1 Time 2 Var – Total time Distance Record time Speed Record ? Fred 12. 00 12. 87 0. 87 3 Y Emily 12. 00 12. 98 0. 98 3 N Sarah 12. 00 12. 76 0. 76 3 N Bob 12. 08 12. 88 0. 80 3 Y
Python Code – Athlete example • • • • • • #program to collect 2 athlete times items timelist = [] max. Length. List = 4 print 'Welcome to my athletics program' distance=input('Please enter distance of the track') limit=input ('What is the fastest time? ') while len(timelist) < max. Length. List: Time 1=input ('Please enter the time passed camera 1: ') Time 2=input ('Please enter the time passed camera 2: ') speed= (distance/(Time 2 -Time 1)) if speed >=limit: print ('The Average speed is', speed) #Round up the speed to nearest decimal point speed = '%. 1 f'%speed #APPEND IF THE Athlete IS SPEEDING timelist. append(reg_str) timelist. append(speed) else : print('Not speeding - this athlete is too slow ') #PRINT THE LIST OF SPEEDING - NOTICE TIMELIST PRINTS IN FROM 0: 2 TO GIVE FIRST 2 VALUES ONWARDS ! print "The following Athletes broken the record; " print 'Athlete 1 ', timelist[0: 1], 'Average Speed', timelist[1: 2], 'Secs' print 'Athlete 2 ', timelist[2: 3], 'Average Speed', timelist[3: 4], 'Secs'