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

CPSC 231: Assignment 5 (Worth 3%)

 

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 is the same the ones for the previous assignment.

Grading: Working submissions

Assignments that receive a 'B-'

In the Assignment5 directory you will find a partially completed version of the assignment called 'lucky.p'.  You are to use this program as a starting point for your own assignment.  To receive credit for the 'B-' version of the assignment you must implement all the operations that were listed in the 'C' version previous assignment but it must be done by implementing the following functions and procedures listed below and it must be able to rerun itself (as described in the second feature of the previous assignment).  In addition you need to write two addition procedures: an introduction procedure that runs when the program starts and describes what it is supposed to do and some sort of concluding procedure that runs when the program ends and informs the user that they have exited.  It is mandatory that you implement the functions and procedures as they are described below in order to get credit for this assignment.

Module to implement Type of module Parameters (input) Function return value Description of the module
getAge Procedure age Not applicable
  • Display a prompt to the user to enter his or her age.
  • Read in the age of the user.
determineAgeModifier Function age ageModifier
  • Calculate and return the age modifier by finding the remainder of the age divided by 101.
getGender Procedure gender Not applicable
  • Display a prompt to the user to enter their gender.
  • Read in the gender of the user.
determineGenderModifier Function gender  genderModifier
  • Determine and return the gender modifier based on the specified gender.
getComputer Procedure computerType Not applicable
  • Display a prompt to the user to enter their computer type.
  • Read in the user's computer type.
determineComputerModifier Function computerType computerModifier
  • Determine and return the computer modifier depending upon the computer type.
generateLuckySum Function ageModifier, genderModifier, computerModifier luckySum
  • Calculate and return the lucky sum which is the sum of the age, gender and computer modifiers.
generateRandomSum Function None randomSum (+/- 100)
  • Randomly determine whether the value of plus or minus 100 which will be added to the lucky sum and return this value.
generateLuckyNumber Function luckySum luckyNumber
  • Determine and return the lucky number which is based on the sum of the value returned by: generateLuckySum and generateRandomSum.

Your assignment will be reduced by a letter 'step' for each of the above modules that were missed down to a minimum grade of a 'D' (assuming that the program can be compiled and it appears that you put a reasonable effort into it).

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

The program performs some rudimentary error checking: These assignments fulfill all of the requirements for a 'B-' 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): Your program performs the error checking for the user's age that was described in feature 1A of the previous assignment.  It will check if the age is valid in two functions that you will write called 'ageTooLow' and 'ageTooHigh' each which will take as a parameter the age that the user entered in the 'getAge' procedure.  The first function will return true if the age is less than zero and false otherwise.  The second function will return true if the age is greater than 114 and false otherwise.  The return value of  these functions will be used in the getAge module to determine if an error message needs to be displayed and if a default value needs to be assigned for the age.
   
 
  1. (Worth 1 letter step): Your program performs the error checking for the user's stated gender that was described in feature 1B of the previous assignment.  It will check if the gender is valid in the function that you will write called 'isGenderValid' which will take as a parameter the gender that the user entered in the 'getGender' module and will return true if the gender is valid (male or female) or it will return false otherwise.  The return value of function isGenderValid will be used in the getGender module to determine if an error message will be displayed and if a default value needs to be assigned for the gender. 
     
 
  1. (Worth 1 letter step): Your program performs the error checking for the user's computer type that was described in feature 1C of the previous assignment.  It will check if the computer type is valid in the function that you will write called 'isComputerValid' which will take as a parameter the computer type that the user entered in the 'getComputer' module and will return true if the computer type is valid (one of the types listed in the previous assignment) or it will return false otherwise.  The return value of function isComputerValid will be used in the getComputer module to determine if an error message will be displayed and if a default value will be assigned for the computer type. 

Tracing the function and procedure calls

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 'B-' 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.  Omitting the paper printout of your assignment will result in the loss of a letter 'step'.  Omitting the electronic submission of your program will only allow you to receive a maximum grade of D-.

  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/assignment5.  As previously mentioned you must use the source code in the lucky.p file.