Lecture notes for the Introduction to Computer Science I by James Tam Return to the course web page

 

CPSC 231: Assignment 4 (Due Thursday June 5: Worth 4%)

 

Description

For this assignment you are to create a program that will  ask the user a series of questions which will allow it to calculate the projected life expectancy for that person.

Start with a  base for the expected lifespan of 72 years.  Modify the value for the expected lifespan with the calculations listed below in the order that they are listed.

1. Gender:  

2. Marital status:

3. Number of children:

4. Miscellaneous filler information:

The resulting value will be the person's expected lifespan of the person in years.  For the base assignment this number will be expressed in the form of a real number (e.g., 75.5 years).  For the more advanced submissions it will be expressed in integer form years and days (e.g., 75 years, 183 days).  This is described in detail in the "Grading" section (additional feature #3).

1 Note: This formula has been totally made-up for this assignment and should not be interpreted as even a rough gauge for how long that a particular person will live!

 

Relevant files

You will find two executable solutions to this assignment in the directory: /home/231/assignments/assignment4/ called "A+version" and "B-version" that implement the best possible assignment and the base assignment respectively.

 

Grading

Base assignment: Grade B-

The program fulfills all of the above requirements (it gets the necessary information from the user, determines how many years that this person will live and displays this information onscreen).

 

Additional features:

1. Error checking: Your program must check for and handle the following error conditions:

If your program checks for and handles all of the above error conditions then your mark will be increased by 3 letter steps (a full letter grade e.g., from  "B-" to "A-".  If your program misses 1 of the above error conditions then your mark will be increased by 2 letter steps (e.g., from "B-" to "B+").    If your program misses 2 of the above error conditions then your mark will be increased by 1 letter step (e.g., from "B-" to "B").  You will get no extra marks if your program misses 3 or more of the above error conditions.

2. Program automatically repeats:  Rather than requiring the person to rerun the executable every time that he or she wishes to calculate an expected lifespan the program will automatically ask the user if he or she wishes to perform another calculation.  If the person enters no ('n') then the program will end.  The successful implementation of this feature will result in the increase of one letter step (e.g., from "A-" to "A").

3. Program displays the person's expected lifespan in years and days:   To fulfill the requirements for this feature, rather than displaying the expected lifespan as a real value in years it will display the person's expected lifespan in years and days with both values shown in integer form.  The program starts by displaying the person's expected lifespan in years (rounded down).   For the remaining rational portion it will then tabulate the equivalent value in days (rounded up).    You can ignore the effect of leap year for this assignment and assume that each year will have 365 days.  For example, suppose that the program determines that life expectancy for the person is 75.5 years.  With this feature the program will indicate that the person is expected to live 75 years and 183 days (0.5 years * 365 days/year = 182.5 days or 183 days when rounded up).  The successful implementation of this feature will result in the increase of one letter step (e.g., from "A" to "A+").

The successful implementation of the base assignment, all the error checking/handling, the ability of the program to auto-repeat and the display of information in years and days may result in a grade of A+ (GPA = 4.3) for this assignment.  This assumes that the other requirements listed below have also be met satisfactorily.  It is your responsibility to clearly indicated to your marker which features that you have implemented for your assignment submission.  You can do this by attaching a note or by typing this information into the program documentation.

 

Other submission requirements

1. Good coding style and documentation:  They will play a role in determining your final grade for this assignment.  Your grade can be reduced by a letter step e.g., "A" to "A-" for poor programming style.

 

Required test cases

You must run the following test cases in the typescript that you hand to your marker.   Failure to completely test your program with all of these caes may result in a grade reduction of one letter step or more.

1. Case One:

    Gender: Male

    Marital status: Married twice, not currently married

    Number of children: None

    Miscellaneous information: $60,000 annual income, shoe size of 6.

 

        2. Case Two:   

    Gender: Male

    Marital status: Never married

    Number of children: 1

    Miscellaneous information: $60,000 annual income, shoe size of 6.

 

        3. Case Three

            Gender: Male

            Marital status: Married 16 times, not currently married

            Number of children: 3

            Miscellaneous information: $15,000 annual income, shoe size of 13.

 

        4. Case Four

            Gender: Female

            Marital status: Married once, not currently married

            Number of children: 2

            Miscellaneous information: $75,000 annual income, shoe size of 9.

 

        5. Case Five

            Gender: Female

            Marital status: Married 6 times, is currently married

            Number of children: 14

            Miscellaneous information: $60,000 annual income, shoe size of 8.

If you implement the additional features that were described above, then make sure that you run extra test cases in your script that will clearly and fully demonstrate the execution of all of these extras.  Also, make sure you clearly show in your script when each test case is being run.  You can do this through the use of white space (by hitting the return key while running the script) and by annotating the printout by hand.

 

New Concepts to be applied for the assignment

 

Related links

Here are some web sites that also predict your expected lifespan.  I included them so that you could better understand how these types of programs work.  It is up to you to determine how seriously you want to take the resulting figures.

    http://gosset.wharton.upenn.edu/~foster/mortality/perl/CalcForm.html

    http://www.deathclock.com/

    http://www.msnbc.com/modules/quizzes/longevity.asp