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

CPSC 231: Assignment 4 (Worth 3%)

 

New Concepts to be applied for the assignment

  1. Program documentation
  2. Formulas
  3. Decision making constructs
  4. Loops

 

Determining your happydex rating

Ever wonder how happy a person that you are, here's your chance to find out by determining how you rate on the happy index scale the 'happydex'.1

Your program will ask the user three sets of questions.  For each question a numerical 'modifier' will be tabulated that is used in the overall happydex rating.

1) The person's birth information

2) The type of car driven

3) The person's phone number

1) Birth information

There are two parts to this section: the month of birth and the year of birth.  The birth month will be entered as a numeric value corresponding to the order of the month e.g., January is the first month so the person would enter 1, February is the second month so the person would enter 2 etc. The year of birth is entered as a four digit integer value.  The birth modifier is calculated by adding the birth information together and then calculating the remainder of this sum divided by 102.  For example if the person was born on November, 1976 then the birth modifier would be calculated as follows:

birth modifier

 = (11 + 1976) MODULO 102

                   = 1987 MODULO 102
  = 49

 

 

 

2) Vehicle information

The program will prompt the user to enter in a single character based upon the type of car that he or she drives:

Vehicle driven Character to input Vehicle modifier
Other (not listed below) e.g., Minivan 'O' or 'o' 40
No car ''N' or n' 50
Compact e.g., Smart Fourtwo 'C' or 'c' 60
Jeep/SUV e.g., Toyota RAV4 'J' or 'j' 70
Sports car e.g., Eagle Talon 'S' or 's' 80
Luxury car e.g., Rolls Royce Phantom 'L' or 'l' 90
Hybrid e.g., Chevy Silverado 'H' or 'h' 100

3) Phone number

The final question requires that the person enters that last two digits of their home or primary phone number.  The phone modifier is equal to this number.

The happydex value is simply a sum of the three modifiers generated above.

The program will then display the numerical happydex value as well as indicating what happiness category that the person falls under:

Happydex value Description  
0 - 99 Content: You have an equal balance of happy and sad events in your life.
100 - 199 Glad:  Life almost always looks good to you.
200 - 300 Ecstatic.  Homer Simpson's famous exclamation best describes your life: 'Woohoo!'

Grading

Assignments that receive a 'C'

These assignments implement all of the required functionality listed above.  Assignment submissions must follow also follow good coding style and be fully documented.  

 

Extra features:

Implementing either of the features listed below can increase your grade by a full letter (e.g., 'C' to 'B').  Implementing both features correctly can allow you the potential to receive a grade of 'A' (style and documentation standards must still be met).

Feature 1: These assignments fulfill all of the requirements for a 'C' level submission and performs some rudimentary error checking.  If an invalid value is entered the program will generate an appropriate error message and a default value will be used by the program.

  1. The birth month must be an integer value between 1 and 12 (inclusive).  If a value is given outside of this range then the program will set the month to a default value of 11. 
  2. The year of birth must be a value between 1890 (the year of birth of the oldest person) and 2005 (the current year) otherwise the default year of 1976 will be used instead.
  3. The type of vehicle must fall into one of the above categories.  If another value is entered then the program will assume that the person drives a sports car and set the car modifier to 80.
  4. The two digit value for the phone number must lie between 00 - 99 (inclusive).  If additional digits or a negative value is entered then the program will use the default value of 43.

Missing one of the above cases will reduce your maximum letter grade to a 'B-'.  Missing two cases will reduce your maximum letter grade to a 'C+'.  Missing more than two cases (checking only 1 or 2 error conditions will not provide you with any grade increase over the 'C' version).  It is however not expected that your program can determine if the type of data that was entered is correct  e.g., at this point it's acceptable if your program crashes if the person enters a character instead of an integer.  While some of the better commercial programs do deal with issues like this, at this point it would be far too difficult to require you to implement a solution for this problem.     

Feature 2: These assignments fulfill all of the requirements for 'C' level submission but it automatically re-runs itself.  Each time that a calculation has been performed the program will prompt the user if he or she wishes to run the program again or if they want to exit the program.

 

Other submission requirements

In addition to having fulfill the generic assignment requirements the requirements specific to this assignment include:

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 or more (e.g., 'A' to 'A-' for poor programming style such as employing poor naming conventions for identifiers, insufficient documentation or the use of global variables).  For additional details see the marking guide for coding style.

2. Include a README file in your submission:  For this assignment your README file must indicate what grade level has been completed (A, B or C).  This will allow your marker to quickly determine what he or she must look for and speed up the marking process.

3. Assignments (source code/'dot-p' file and the README file) must be electronically submitted via submit.  In addition a paper print out of the source code and README must be handed into the assignment drop box (located on the second floor of the Math Sciences building) for the tutorial that you are registered in.  Electronically submitting the assignment allows your marker to run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code.

 

Sample Executable

You can run a sample executable called 'happy' which can be found in Unix in the directory: /home/231/assignments/assignment4

1 Note: The happydex is to be used for entertainment purposes only and neither I nor the University of Calgary provides any express or implicit guarantees that the numbers generated will actually predict the amount of joy that you will receive in this life..