Homework Assignment 5

Extending Programs with File Input and Output


CS 1510
Introduction to Computing
Fall Semester 2015


Due: Thursday, October 29, by 11:15 PM


Introduction

This assignment asks you to extend a working program with new features. This week, we studied file input and output (I/O), so let's extend a couple of programs to process multiple inputs from files. You will extend Process a CSV record you wrote during Lab #6 and the body mass index program you wrote for Homework 2. The BMI program was also discussed in connection with chapter two as the major topic of class #6 (09/10/15).

  1. Lab #6: Process a CSV record...

  2. HW #2: Body Mass Index - BMI.

  3. Class #6: BMI info - (09/10/15) - BMI hints.

This assignment requires you to have a working versions of grade_csv.py and bodyMassIndex.py. If your Homework 2 and Lab 6 solutions do not work correctly, please fix them before starting this assignment. If you feel it would take too long to fix your programs, you may use my solution or have me look at your non-working code solution and tell you how to fix it and make it work. Email me at jacobson@cs.uni.edu if you want to do that.

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 I/O 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.



Spec 1: Grade Report from CSV records file

Make a copy of grade_csv.py from Lab 6 and call it gradeReport.py. Put the copy in your Homework 5 folder and use the copy for this assignment.

Modify the lab 6 grade program to read from a data file and produce output to the screen as shown in the example that follows:

For example, I have a text file called fileOfGrades.txt that contains the following:

Mark Jacobson,20,17,20
Mortimur Snurd,20,19,18,17,16,15,14,13
Rosa Luxemburg,18,15,20,10,12
John Atanasoff,20,20,20,20,20,20,20
Grace Hopper,20,20,20,20,20,20

Here is how your program should behave:

    Enter filename: fileOfGrades.txt

    -------------------------------------------------------
                Grade Report for Programs 
    -------------------------------------------------------
    Jacobson, Mark      19.0 <--- 20,17,20
    Snurd, Mortimur     16.5 <--- 20,19,18,17,16,15,14,13
    Luxemburg, Rosa     15.0 <--- 18,15,20,10,12
    Atanasoff, John     20.0 <--- 20,20,20,20,20,20,20
    Hopper, Grace       20.0 <--- 20,20,20,20,20,20
    -------------------------------------------------------


Hint in response to student question: Column Alignment of the Averages...
One idea, one possible way to use to help with the formatting.

I typed fileOfGrades.txt. The program typed the rest.



Spec 2: Body Mass Index Calculations

Make a copy of body_mass_index.py from Homework 3. Put the copy in your Homework 7 folder and use the copy for this assignment.

Modify your body mass index program to read patient data from a data file, calculate the body mass index for each, and print the results to a file. Ask the user for the names of the input and output files.

For example, I have a text file called patient_data.txt. Here is how your program should behave:

    >>> 
    Enter input filename : patient_data.txt
    Enter output filename: bmiOut1.txt
    >>> 

I typed the two filenames. The result is a new file called bmiOut1.txt. Again, you can produce better-looking output, if you'd like.

Be aware that the input file might include:

    Data for a person who is 4 or 5 or 6 feet and 10 or 11 inches tall.
                                                  --    --

    Data for a person who is less than 100 pounds in weight, say 97 pounds.
                                                                 --
5,10,174
6,1,210
4,7,97
6,11,255
5,9,155


Demonstration of Correctness

Start a fresh Python shell. Run the final versions of your programs on two input files each:

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



Deliverables

By the due date and time, submit:

Use the on-line submission system. files - Input and Output Files - BMI reports and Grade reports

Make sure that your program meets the course programming standards.