CSSE 120 -- Intro. to Software Development

Homework 10

  1. There is no new reading for the next session.
  2. There is no Angel quiz for the next session.
  3. Programming problem: Speed Reading: Average numbers from an input file

    This problem requires you to combine the ideas of exception handling, defining functions, reading from files, and using a graphics window to get user input.

    Your task is to read numbers from a file and calculate the mean of the numbers. Unfortunately, the file is a bit malformed. The numbers are generated by a radar gun that measures the speed of each vehicle on the road coming up the hill from the SRC. Due to an intermittent open circuit occasionally multiple numbers are written on a single line, like this:

    23.2 15.6 19.8

    Occasionally the radar gun also puts a single stray character at the end of a number, like 17.9a instead of 17.9, or 24.9$ instead of 24.9. A sample input file is available here: speeds.txt.

    1. Write a program called fileAverages.py that calculates the mean of numbers in a file.
    2. Your program should ask the user for the name of the input file to process. Rather than using “console” input, your program should use a GUI similar to the one in Figures 5.9 and 5.10 on pages 150 and 151 of Zelle’s text book. Use an Entry object (Zelle, page 148) to accept the input file name from the user.
    3. Your program should use four functions as in this template.  You are advised to download and use the template.
    4. Your program should display the final average in the GUI window. Hint: You can use the setText() method to change the displayed value of a string that has already been drawn.
    5. Test your program using some small text files that you have created using a text editor, like Notepad. Your small files should include simple examples (like one number per line), and more complicated ones demonstrating the possible malformed data discussed above.
    6. Once you are confident that your program works for small test cases, try it on our sample file.

    Submit your program by uploading your fileAverages.py file to the fileAverages drop box in the Homework 10 folder on ANGEL.