Question

In: Computer Science

Hometown City USA is analyzing traffic patterns to determine whether traffic lights are necessary at tracked...

Hometown City USA is analyzing traffic patterns to determine whether traffic lights are necessary at tracked intersections. Each tracked intersection has a data file where each line contains the number of cars passing through that intersection on a given day. The data collected can cover any number of days; there can be any number of lines per file. Design an algorithm solution to read a given data file, calculate, and display the following:
number of days monitored at the intersection
maximum number of cars passing through the intersection on a tracked day
average cars per day passing through the intersection
Include the following requirements in your algorithm design:
Use a starting main module to create needed variables, read data from file, and display count and average of data in the file.
Use only simple data types, not arrays or lists in your algorithm.
In a single loop to read from the file, use an accumulator and counter to keep track of data read from file for calculating the average. Do not display data contained in the file; only calculate and display the number of days, highest number of cars for a day, and average number of cars per day contained in the file.
Remember to close the file when reading is complete

Solutions

Expert Solution

1. Begin

2. Open the input file in read mode.

// count is for counting the number of days

//sum is for adding the total number of cars passed through that intersection

//high is set to -1 for finding the highest number of cars per day

// marker is set to True

3. Initialize count =0 and sum=0, high=-1, marker=True

4. While (marker) //Loop when True

// reads the record one by one to variable f

5. Read record from file to f.

6. IF EOF Then

7. exit from While

8. ELSE

9. count=count+1 // Increment the count

10. sum=sum+f //sum is added with the number of cars passed on that day

11. IF(f>high) Then // If f is a bigger value, replace high with new value of f

12. high=f

13. End IF

14. End IF

15 End While

16. Close the Input File

17. Calculate average=sum/count // getting the average number of cars per day

18. Print ("Number of days=",Count)

19. Print ("Highest number of cars for a day=",high)

20. Print("Average number of cars for a day=",average)

21. End


Related Solutions

The number of traffic lights malfunctioning daily in any city can be said to satisfy the...
The number of traffic lights malfunctioning daily in any city can be said to satisfy the binomial distribution. However, the rate at which “successes” (traffic lights malfunctioning) and “failures” (traffic lights not malfunctioning) occurs nearly instantaneously, with nearly nonzero probability, such that the expected value approaches a constant. It is known that the second moments (E[X2]) of the number of daily malfunctioning traffic lights in Philadelphia, Pittsburgh, and Erie respectively are 72, 56, and 42. The malfunctioning of traffic lights...
The city of Metropolis is considering replacing incandescent bulbs in traffic lights with light-emitting diode (LED)...
The city of Metropolis is considering replacing incandescent bulbs in traffic lights with light-emitting diode (LED) lights because they use significantly less energy and last much longer without abrupt failure. Currently Metropolis has 80,000 incandescent bulbs in traffic lights at approximately 12,000 intersections. It is estimated that replacing all the incandescent bulbs with LED will cost $46.02 million. However, the investment is also estimated to save the city $8.85 million per year in energy costs. Answer the following questions on...
Question 2011 pts What information do bridges use to determine whether to forward traffic? Group of...
Question 2011 pts What information do bridges use to determine whether to forward traffic? Group of answer choices MAC addresses IP addresses traffic conditions at the time nothing because bridges forward all traffic Question 2021 pts A technician is at a small facility that has five computers connected to a central switch and accessing a single server for file and print sharing. One computer becomes unable to connect to the network, while the other four are still connecting properly. Which...
You have been asked by your boss to determine whether it is necessary to show earnings...
You have been asked by your boss to determine whether it is necessary to show earnings per share (EPS) on the financial statements when the company is not public and not governed by the Securities & Exchange Commission (SEC). What will you tell your boss? (US GAAP ISSUE) AN ASC NUMBER MUST BE USED AS A CITATION REFERENCE EACH GAAP ASSIGNMENT WILL HAVE THE FOLLOWING FORMAT: PROBLEM TO BE RESEARCHED: What is the question being asked? SOURCES FOR RESEARCH: (EX....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT