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

CPSC 231: Assignment 4 (Worth 3%)

Score Grade
62 - 64 A
58 - 61 A-
54 - 57 B+
50 - 53 B
45 - 49 B-
41 - 44 C+
37 - 40 C
33 - 36 C-
28 - 32 D+
21 - 27 D
11 - 20 D-
0  -  10 F

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've all 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 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 lucky sum falls under.

The lucky sum Lucky number
  200 - 500 7
  501 - 700 13
  701 - 900 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.  Lucky number is...7!

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.

Features to be implemented (you will also be graded on other criteria such as coding style and providing program documentation as listed in the marking guide):

Basic features

 
  1. The first time that game is run it displays an introduction to game with a brief description of the rules: 1 mark
 
  1. When the player quits the game it displays a brief conclusion/signoff message: 1 mark
 
  1. Prompts the user to enter their age: 1 mark
 
  1. Reads in the age of the user: 1 mark
 
  1. Calculates the age modifier: 2 marks
 
  1. Prompts the user to enter their gender: 1 mark
 
  1. Reads in the gender of the user: 1 mark
 
  1. Determines the gender modifier: 2 marks
 
  1. Prompts the user to enter their computer  type: 1 mark
 
  1. Reads in the computer type entered by the user: 1 mark
 
  1. Determines the computer modifier: 2 marks
 
  1. Calculates the lucky sum: 2 marks
 
  1. Determines the user's lucky number: 2 marks
 
  1. Displays the user's lucky number: 1 mark

Error checking

 
  1. Checks if the user wants to skip the question regarding their age and sets the age to a default value.
   
  1. Determines when the user enters an age below the minimum allowable age (zero) and displays a message indicating that the program will skip the age question: 2 marks
   
  1. Determines when the user enters an age above the maximum allowable age (114) and displays a message indicating that the program will skip the age question: 2 marks
   
  1. (In order to get credit for this feature, the program must properly check for one or both of the above conditions). If a value is outside the allowable range then the age is set to the default of 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): 1 mark
 
  1. Checks if the user wants to skip the question regarding their gender and it sets the gender to a default value.
   
  1. Determines if the user entered a value other than male or female for gender and displays a message indicating that the program will skip the gender question: 2 marks
   
  1. (In order to get credit for this feature, the program must be able to detect when the user has chosen to skip the gender question). If the user chooses to skip the gender question then the program will set the gender to the default, male and then determine the value for the gender modifier: 1 mark
 
  1. Checks if the user wants to skip the question about their computer and sets the computer to a default value.
   
  1. Determines if the user entered a value other than one of the listed types and displays a message indicating that the program will skip the computer question: 4 marks
   
  1. (In order to get credit for this feature, the program must be able to detect when the user has chosen to skip the computer question). If the user chooses to skip the computer question then the program will set the computer type to the default of UNIX and determine the computer modifier based on the computer type: 1 mark

Other features: improved ease of use

 
  1. Program allows for upper or lower case input for the gender and computer type (and for the prompt to re-run the program if that was implemented): 4 marks
 
  1. Program can automatically re-run 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: 4 marks

Submission requirements

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

  1. Include a README file in your submission:  For this assignment you need to include a file called 'README' which includes your contact information: your name, university identification number and UNIX login name as well as all the features of the program that you implemented so that your marker knows whose assignment that he or she is marking and what features to look for.

  2. Assignments (source code/'dot-p' file and the README file) must be electronically submitted.  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 compile and 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. 

  3. 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.

To help make sure that you haven't missed anything here is a checklist of items to be used in marking.

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.