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

CPSC 231: Assignment 5 (Worth 3%)

Score Grade
59 - 60 A
57 - 58 A-
54 - 56 B+
51 - 53 B
47 - 50 B-
43 - 46 C+
39 - 42 C
33 - 38 C-
27 - 32 D+
21 - 26 D
11 - 20 D-
0  -  10 F

New concepts to be applied for the assignment

  1. Problem decomposition through the use of functions and procedures

Determining your lucky number

Unless otherwise indicated the features of your program for this assignment are the same the ones for the previous assignment.

Modules 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):

Module Type Input / parameters Function return value Description Marks for implementing the module
main procedure NA NA The starting point of execution for the program NA - it will be given to you to help you start your program.
initialize procedure runAnswer (char)

age (integer):

ageModifier (integer):

gender (char):

genderModifier (integer):

computer (char):

computerModifier (integer):

luckySum (integer):

luckyNumber (integer)

NA Set variables to default starting values. If you have additional variables declared that need to be initialized then you can also pass them to this procedure. NA - you need to implement this module as part of good programming practice.
introduction procedure none NA Describe how the program works.  The procedure runs once as the program first runs. 1 mark
conclusion procedure none NA Display a signoff message so that the user knows that the program has ended. 1 mark
askAge procedure age (integer) NA Prompts the user to enter their age (1 mark), reads in the value entered by the user (1 mark). If after calling function 'skipAgeQuestion' its determined that the user wants to skip this question this module sets the age to the default (1 mark) 3 marks
skipAgeQuestion function age (integer) Boolean If the user enters an age that is outside the range for a normal allowable age then this function has determined that the user wants to skip the age question and it will return true. If the user enters an age that is within the allowable age then this function has determined that the user does not want to skip the age question and it will return false.  4 marks
determineAgeModifer function age (integer) ageModifier (integer) Based on the age entered by the user, this procedure will determine what the age modifier will be and return this value to its caller (2 marks). 2 marks
askGender procedure gender (char) NA Prompts the user to enter their gender (1 marks), reads in the value entered by the user (1 mark). If after calling function 'skipGenderQuestion' its determined that the user wants to skip this question this module sets the gender to the default (1 mark) 3 marks
skipGenderQuestion function gender (char) Boolean If the user enters a gender other than male or female then this function has determined that the user wants to skip the gender question and it will return true. If the user enters male or female then this function has determined that the user does not want to skip the gender question and it will return false.  2 marks
determineGenderModifier function gender (char) genderModifier (integer) Based on the gender entered by the user, this procedure will determine what the gender modifier will be and return this value to its caller (2 marks). 2 marks
askComputer procedure computer (char) NA Prompts the user to enter their computer type (1 marks), reads in the value entered by the user (1 mark). If after calling function 'skipComputerQuestion' its determined that the user wants to skip this question this module sets the computer type to the default (1 mark) 3 marks
skipComputerQuestion function computer (char) Boolean If the user enters a computer type that is not one of the allowable types then this function has determined that the user wants to skip the computer question and it will return true. If the user does enter one of the allowable computer types then this function has determined that the user does not want to skip the computer question and it will return false.  4 marks
determineComputerModifier function computer (char) computerModifer (integer) Based on the computer type entered by the user, this procedure will determine what the computer modifier will be and return this value to its caller (2 marks). 2 marks
generateLuckySum function ageModifier (integer):

genderModifier (integer):

computerModifier(integer)

 

luckySum (integer) This function will return the sum of the three parameters (the three modifiers). 2 marks
generateLuckyNumber function luckySum (integer) luckyNumber(integer) Based on the luckySum parameter this function will determine and return the user's lucky number back to its caller. 2 marks
displayLuckyNumber procedure luckyNumber (integer) NA Displays the user's lucky number 1 mark

Finally if you can use the pre-created function UpCase to convert any lower case character input entered by the user (for the gender, computer type and prompt to re-run the program) to upper case values (so that you're program can handle upper or lower case input) you receive an extra 4 marks.

To help you visualize the structure of your program I've included a diagram that shows the hierarchy of calls for the modules:

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.  A sample executable 'lucky' can be found in UNIX under the directory: /home/231/tamj/assignments/assignment5. Also there will be a skeleton program called 'lucky.p' that you must use as the starting point for your own program.