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

CPSC 233: Assignment 1 (Worth 2%)

 

Due Wednesday Sept 22

New concepts to be applied for the assignment

  1. Console input and output
  2. Program documentation
  3. Formulas
  4. Decision making constructs
  5. Loops

Writing a lucky number generator

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 four questions:

1) The person's age

2) The person's pet

3) The first character of the person's last name

4) The person's current level of education

1) Age

This value must be a positive integer between 1 and 113 (inclusive).  This value will stored as-is in an integer variable and is used to determine the modifier resulting from the person's age.

2) Type of pet

The person indicates the type of pet that they have: cat, dog, fish, bird, other or none.

Color

Pet modifier

none   5
cat 10
dog 11
fish 13
bird 15
other 18

3) First character of last name

The person types in the first character of their last name.

Letter

Name modifier

A 65
B 66
C' 67
: :
Z 90

4) Current level of education

For this question the program will ask the person to indicate the level of education that the person is currently enrolled in or the highest level that has been completed (if the person is not currently a student).

Level of education

Education modifier

High school

12

Undergraduate post-secondary

16

Graduate: Masters program

18

Graduate: Doctoral program

21

The lucky number generator will perform a calculation that is based on the answers to these four questions:

    Lucky number = (age modifier x pet modifier) modulo (name modifier x education modifier)

 

Example calculations are shown below:

Responses for the first example Modifier
Age = 113 113
Pet = Other 18
Initial = A 65
Education = high school 12
Lucky number = (113 * 18) modulo (65 * 12) = 2034 % 780 = 474

 

Responses for the second example Modifier
Age = 27 27
Pet = None 5
Initial = T 84
Education = masters 18
Lucky number = (27 * 5) modulo (84 * 18) = 135 % 1512 = 135

 

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 must be fully documented.   After calculating a lucky number the program will prompt the user if he or she wishes to calculate another one.

Assignments that receive a 'B'

These assignments fulfill all of the requirements for a 'C' level submission and performs some rudimentary error checking:

  1. Age must be an integer value between 1 and 113 years (inclusive).  If a value is given outside of this range then the program will continue asking the user to enter a value that is within the allowable range.
  1. The response to the type of pet owned must be of the following:

If a character other than c, d, f, b, o or n is entered (upper or lower case) then the program will continue asking the user to enter in one of the above responses.

  1. The first character of the last name must be a valid alphabetic character (upper or lower case) and if it is not the program will continue asking the user to enter in an alphabetic character.
  1. The level of education must fall into one of the following categories:

If another value is given for the level of education then the program will continue asking the user to enter in one of the above responses.  As with the previous two cases the user can enter in the information in either upper or lower case format.

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 until the end of the term.

Assignments that receive an 'A'

These assignments fulfill all of the requirements for 'B' level submission but also allow the user to skip any or all of the questions.   This allows the person to skip questions that her or she may not feel comfortable answering within feeling "trapped" by the program (i.e., the program interrogates the person forever until a response is provided).  For each question that is skipped by the user, the program will provide a default answer.

Question Indicator to skip the question Default value
Age Negative value for age 27
Pet Pound sign (#) none
First character of last name Pound sign (#) T
Education Pound sign (#) masters

 

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

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 and the README file) must be electronically submitted via submit.  In addition a paper print out of the source code must be handed into the assignment drop box for the lab that you are registered in (located on the second floor of the Math Sciences building).  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 "Lucky" which can be found in Unix in the directory: /home/233/assignments/assignment1

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.