Homework Assignment 4

Using Control of Flow to Extend Programs


CS 1510
Introduction to Computing
Fall Semester 2014


Due: Thursday, September 25, at 10:00 AM


Introduction

Programmers often extend or modify existing programs. This assignment asks you to add code to a working program to implement new features, using ideas we studied this week. You will extend the quarterback passer rating program you wrote for Homework 2.

This assignment requires you to have a working version of passing-efficiency.py. If your Homework 2 solution did not work correctly, please fix it before starting this assignment. If you feel it would take too long to fix your program, you may use my solution, which was included in Session 6's code file. E-mail me now to let me know if you do that.

Each task adds you to create a new version of the program and add a specific new feature. Do the tasks in order. If for any reason you do not complete the whole assignment, submit only the versions you complete, and use your final version to create the interaction that demonstrates your work.

I encourage you to personalize your program and make it your own. Feel free to use all the things you are learning in class to make your program as good as you would like. However, be sure not to change the input/output specification, especially the number and order of the data values your program reads from the user.

And, as always, be sure to meet the course programming standards.



Task 1: Classify the Program's Output

Make a copy of passing_efficiency.py called passing_efficiency_v2.py and use the copy for this task.

It can be hard to understand the quality of a quarterback's performance from the raw passing efficiency rating. In the NFL,

Modify your program so that, after calculating the passing efficiency, it prints both the number and a statement about the quality of the performance.

For example:

    --------------------------
    Passing efficiency = 95.66    This is a Top Ten-caliber performance!
    --------------------------

You can use the range test pattern we saw in Session 8 when discussing the letter grade problem from Lab 4.



Task 2: Validate the Program's Input

Make a copy of passing_efficiency_v2.py called passing_efficiency_v3.py and use the copy for this task.

The passer rating program reads five inputs from the user, in this order:

  1. the number of passes completed
  2. the number of passes attempted
  3. total passing yards
  4. number of touchdown passes
  5. number of interceptions

As specified, this program allows invalid data. For instance, in a real game or season,

Modify your program to ensure that these conditions are satisfied.

The basic algorithm for validating data from a user looks like this:

The key to writing code for this algorithm is writing the boolean condition for the while loop.



Task 3: Allow the User to Enter Multiple Players

Make a copy of passing_efficiency_v3.py called passing_efficiency_v4.py and use the copy for this task.

The user may want to calculate passing efficiency ratings for multiple players in a single execution of the program. This would make it easier to compare the performances of several players at once, or prepare a report.

Modify your program so that repeats the input-process-output computation. If the user enters -1 for the number of passes completed, the program terminates.

For example:

    --------------------------
    Passing efficiency   (NFL)
    --------------------------
    Passes completed: 185
    Passes attempted: 313
    Passing yards   : 2450
    Touchdown passes: 21
    Interceptions   : 8
    --------------------------
    Passing efficiency = 95.66    This is a Top Ten-caliber performance!
    --------------------------
    Passes completed: 317
    Passes attempted: 551
    Passing yards   : 3818
    Touchdown passes: 18
    Interceptions   : 27
    --------------------------
    Passing efficiency = 69.37    This is a disastrous performance.
    --------------------------
    Passes completed: -1

    Calculations completed.

You can use a sentinel loop to implement this idea. We discussed two forms of the sentinel loop in Session 8, and you implemented one in Session 8.



Demonstration of Correctness

Start a fresh Python shell. Run the final version of your program using data for at least three different players that demonstrate the correctness of your program. Be sure to make a couple of data-entry errors that demonstrate your input validation code.

You may use data for any players you like. You may also use these values, which fall into three categories of quality:

    185     313     2450     21      8          (Sawyer Kollmorgen, 2012)
    380     628     4343     25     11          (Tom Brady, 2013)
    317     551     3818     18     27          (Eli Manning, 2013)

Save your shell to a text file named interactions.py.



Deliverables

By the due date and time, submit:

Use the on-line submission system.

Make sure that your program meets the course programming standards.



Eugene Wallingford ..... wallingf@cs.uni.edu ..... September 20, 2014