CSSE 120 -- Intro. to Software Development

Homework 10

  1. Complete the assigned reading for the next session (Zelle sections 8.3-8.6).
  2. Complete the Angel quiz over this reading. You'll find this on the course Angel page,
    under Lessons → Homework → Homework 10 → Loop Patterns and Booleans
  3. Speed Reading: Average numbers from an input file.

    This problem requires you to combine the ideas of:

    IMPORTANT: This is a more challenging problem than you have faced before. Because of that, you are allowed to work with a partner, using good pair programming techniques, and you have until session 12 to complete this problem. You will have an additional homework assigned in session 11, so you should attempt to complete this homework before your next class meeting and bring any questions to that meeting.

    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.

    Write a program called fileAverages.py that calculates the mean of numbers in a file. Your program must conform to the following specification.

    1. 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.
    2. Your program should use four functions as in this template.  You should download and use the template as your starting point. (Yes, there are many other ways to write this. We're asking you to follow our specification so you can get practice working with the sort of situations that come up in real world, group projects, where you must compromise on the design.)
    3. 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.
    4. 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. You will turn in your test files with your code.
    5. Once you are confident that your program works for small test cases, try it on our sample file.

    Be sure to include your name, and your partner's name if you have a partner, in a comment in your program. Submit your program by uploading your fileAverages.py file and at least three test input files that you created to the fileAverages drop box in the Homework 10 folder on ANGEL.

  4. BONUS: Augment your program so that it also displays, at the bottom of your window, a bar graph of the data read in, along with a horizontal line showing the mean speed. You are allowed to pass more parameters to your functions to get it to work. For example, you will probably need to pass the window to the  findSumForCountAndLine function for it to display the individual vertical lines as you read them in from the file:

  5. Web link: Debugging, by Dave Agans. A book on debugging that can be helpful to neophytes as well as pros. See the sample chapters at the bottom of the web page!