Question: A radar speed gun is a device used in law - enforcement to measure the speed of moving vehicles in miles per hour. The measured
A radar speed gun is a device used in lawenforcement to measure the speed of moving vehicles in miles per hour. The measured speeds are supposed to be stored in a file, one number per line, as follows:
Unfortunately, due to an intermittent fault, occasionally multiple numbers are written on a single line as follows:
Furthermore, occasionally the radar gun outputs a single stray character such as: z$ or a to illustrate just a few.
Given a file that has radar speed gun readings, write a function averageSpeed to calculate the average of the numbers in the file. Your code must adhere to the following specifications:
aPrompt the user for the name of the input file to process. When the user enters a nonexistent file name, give the user a second chance. After two wrong entries in a row, quit the program with an appropriate message.
b Ignore numbers containing stray characters.
c Ignore any reading for slow vehicles moving at miles per hour or less.
d Print the final average to the console.
e Make use of the functions safeOpen and safeFloat
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
