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
  4. Loops

 

Determining your lucky number

Some people believe that there are some specific numbers that provide them more luck than other numbers.  We all have heard of people who pick the same lottery numbers every week because they believe that these numbers will provide them with a higher probability of winning.  For this assignment you are to write a program that will ask the user a series of questions and generate for the person their very own "lucky number".1

Your program will ask the user three questions:
  1. The person's age
  2. The person's gender
  3. The type of computer owned by the person

For each question a numerical 'modifier' will be computed each of which will play a role in determining the person's lucky number.

Age
  This value must be a positive integer between 0 and 114 (inclusive).  The age modifier will be determined by finding the remainder of dividing the person's age by 101 (to yield a value between 0 - 100).   For example if the person were 28 years old then the age modifier would be calculated in the following fashion:
 
age modifier = 28 MODULO 101
                     = 28
   
Gender
  The program will prompt the user to enter in a character that represents that person's gender.
   
  Gender Gender modifier  
  Male ('M' or 'm') 200  
  Female ('F' or 'f') 300  
   
Type of computer owned
  Again the program will prompt the person to enter in a single character to indicate what type of computer that he or she owns and the modifier will be calculated as follows:
   
  Computer type Computer modifier  
  Apple ('A' or 'a') 100  
  UNIX ('U' or 'u') 200  
  Windows ('W' or 'w') 300  
  Other type computer ('O' or 'o') 400  
  Multiple computers ('M' or 'm') 500  
  No computer ('N' or 'n') 0  

The program will then sum the modifiers generated from each of the above questions and it will either add or subtract 100 from this sum (there's an equal chance for each) to generate the final computed value ('the lucky sum').  The lucky number that the program displays to the user will depend upon which of the following ranges that the final computed value falls under.

The lucky sum Lucky number
  100 - 399 7
  400 - 699 13
  700 - 1000 888

For example:

Q1: Age = 114, age modifier = 13

Q2: Gender = female, gender modifier = 300

Q3: Computer owned = none, computer modifier = 0

Sum of modifiers from each of the above questions = 13 + 300 + 0 = 313. 

Assume that when the program is run it randomly determines that it should subtract 100 from this amount so the resulting final computed value equals 213 (313 - 100) so that the program would display '7' as the lucky number.  (If the program randomly determined that it should add 100 to the sum in the previous step then the final computed value would equal 413 (313 + 100) and the program would display '13' as the lucky number).  Note: Your program shouldn't display the 'lucky sum' to the user but should instead display only the lucky number (showing two numbers would be somewhat confusing).  The exception is when you are testing your program and trying to determine if your lucky sum is calculated correctly.

 

Grading: Working submissions

Assignments that receive a 'C'

These assignments implement all of the required functionality listed above and also follow good coding style and be fully documented as described in the style guidelines.

Marking for assignments that are missing or incorrectly implement the above features:

The minimum grade for a program that compiles (and involved a considerable time and effort to write) is a 'D' regardless of the number of features that may be missing or incorrect.

Extra features:

Implementing all the features below correctly can allow you the potential to receive a grade of 'A' (again style and documentation standards must still be met).

Feature 1, the program performs some rudimentary error checking: These assignments fulfill all of the requirements for a 'C' level submission (or higher) and performs some basic 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. (Worth 2 letter steps) The program checks that the person's age must fall within the range of 0 - 114 (inclusive). Conversely if the age is less than zero or if the age is greater than 114 to receive full credit for this feature your program has to be able to do the following:
   
  • Check if the value entered is within the valid range (upper and lower).  Obviously this feature must be correctly implemented before credit will be granted for the features listed in the following two points.

   
  • If a value is outside the range then an error message will be displayed. 

   
  • If a value is outside the range then the default age is set to 28 (and the age modifier should be calculated in the usual fashion, it should not simply be set using a simple assignment statement because your program won't work correctly in this case if the formula for determining the age modifier is changed later).

    If all of these requirements are fulfilled then you can receive an extra two letter steps.  If the feature listed in the second or third point is missed then you can receive one letter step.  If more than one of these points is missed then you won't receive credit for this feature (you've missed to much and your error checking really doesn't do anything).  If the features listed in the latter two points are correctly implemented but one of the checks for the upper or lower bound was incorrect then you can receive an extra letter step.
   
 
  1. (Worth 1 letter step) The value entered for gender must be one of the following values: 'M', 'm', 'F' or 'f'.  If another value is entered then the program will set the gender value to 'f' and as was the case with the 'C' version the program should determine that the gender modifier is 300.  Again your program should actually determine that the gender was actually set to 'F' or 'f' rather than simply assigning the gender value to 300.  (1 letter step for detecting an incorrect value AND for displaying an error message, setting the gender to 'F' or 'f' and the gender modifier should be calculated in the usual fashion - no marks if any of these parts are missing).
     
 
  1. (Worth 1 letter step) The value entered for computer must be one of the following values: 'A', 'a', 'M', 'm', 'N', 'n', 'O', 'o', 'U', 'u', 'W', 'w'.  If another value is entered then the program will set the computer owned to 'W' or 'w' and as was the case with the 'C' version the program should determine that the computer modifier is 300.  Again the program should actually detect that the type of computer owned is a 'W' or 'w' rather than simply using an assignment statement for the default case.  (1 letter step for detecting an incorrect value AND for displaying an error message, setting the type of computer to 'W' or 'w' and the computer modifier should be calculated in the usual fashion - no marks if any of these parts are missing).

 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, the program is able to re-run itself: These assignments fulfill all of the requirements for 'C' level submission (or higher) and 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. (Worth 2 letter steps).

Grading: Non-working submissions

D submissions

D- submissions

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 (e.g., 'A') and which features have been implemented (e.g., "I have implemented all the features for the 'C' version plus the ability to error check and set a default value and display an error message for the gender and type of computer which amounts to a 'B-' submission).  This will allow your marker to quickly determine what he or she must look for and speed up the marking process.  Also you should include your contact information: your name, university identification number and UNIX login name so that your marker knows whose assignment that he or she is marking.  Omitting the necessary information from this file will result in the loss of a letter 'step' (assuming that the marker can actually figure out who the assignment belongs to).

  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.

  4. As a reminder, you are not allowed to work in groups for this class.   Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following link.

 

Sample Executable

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

1 Note: The Lucky Generator program 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 provide you with greater financial profit or personal gain.
2  What does and doesn't constitute a sufficient amount of time and effort?  It's a judgment call on the part of your marker.  More often than not if you put in a reasonable amount of effort into your assignment and for some reason you just couldn't get it to work then you will receive credit for your work.   An example of when you wouldn't receive credit is when you simply handed someone else's work.  This latter case assumes that you properly cited the other person's work, if you didn't cite your source and tried to claim that it was your own work then it would be an example of academic misconduct (cheating).