CSSE 120 -- Intro. to Software Development

Homework 10

  1. Complete the assigned reading for the next session (Zelle sections 8.3-8.6).
  2. (26 Points) 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. (60 Points) Speed Reading: Average all of the numbers from an input file (perhaps with multiple numbers on some input lines).

    This problem is a bit longer, requiring you to combine the ideas of:

    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

     A sample input file, speeds.txt, is in your project.

    Open the speedReading.py file in the Session10 project that you checked out from SVN in class. Modify it to calculate the arithmetic mean (average) of the numbers in a file. Your program must conform to the following specification:

    1. Your program should use the four functions as given in speedReading.py:
      1. lineSumAndCount()
      2. fileMean()
      3. getInputFile()
      4. main()
    2. When you write more complicated programs, you should be able to test them as you go. Typically, software developers write a set of tests for each small part of the program (thus they are called "unit tests"). We've given you unit tests for the first 2 functions in the file unitTestsSpeedReading.py to help you. So,
      1. Write lineSumAndCount first
      2. Then run unitTestsSpeedReading.py to make sure it works.
      3. Then write and test fileMean in the same way.
      4. Finish up by creating the GUI and testing it on the file speeds.txt in your project by running speedReading.py. The average of the speeds in that file should be around 20.16.
    3. 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.
    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. Yes, there are many other ways that you could 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 often must implement someone else's design design.  We also think that doing it this way will get you to confront some issues and clear up some misunderstandings that you may have about functions.
    6. Commit your file to your SVN repository.
  4. BONUS: (10 Points) 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  line_sum_and_count 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!