A7: Counting the Odds

On This Page


Overview

During this assignment, you will:

  • Write a program that counts the number of even and odd numbers a user enters
  • Organize your program into functions
  • Use pass-by-reference variables

Specifications

Write a program that that counts the number of even and odd numbers a user enters. The program counts the number of zeros entered as well. You must implement the following functions exactly as specified, though you may implement more.

  1. void initialize(int& evenCount, int& oddCount, int& zeroCount): Initializes the counting variables.
  2. void inputNumber(int& num, double min, double max): Gets a number from the user for classification and verifies that the user enters a value between min and max.
  3. If the user enters a value less than min or greater than max, then the function prints an error message that includes the phrase "incorrect value" and then asks the user to re-enter the number. Note that you will need to use a loop for this to work correctly that is in addition to the main loop. When the user enters a correct value, the function returns. Allow the user to enter any value between 0 and 100 for correct values and -1 to exit.

  4. void classifyNumber(int num, int& evenCount, int& oddCount, int& zeroCount): Classifies the number and increments the counts for even, odd and zero numbers.
  5. void showResults(int evenCount, int oddCount, int zeroCount): Reports the results of the computations as shown in the Operation section.
  6. The name of the program source code file must be classifier.cpp and all the code must be in this file.
  7. Whenever the user enters a -1, the program exits.
  8. Do not forget to add block comments before each function declaration (prototype).
  9. Submit your file(s) to WebCT as explained in the section of this document: What to Turn In.

Operation

Enter a positive number or -1 to exit: -5
Incorrect value -- please enter again: 1000
Incorrect value -- please enter again: 5
Enter a positive number or -1 to exit: 4
Enter a positive number or -1 to exit: 3
Enter a positive number or -1 to exit: 2
Enter a positive number or -1 to exit: 1
Enter a positive number or -1 to exit: 0
Enter a positive number or -1 to exit: -1

You entered 3 even numbers, including 1 zeros, and 3 odd numbers

Hints:

  1. The main loop belongs in the main() function
  2. Note that zero is an even number since it is evenly divisible by two.

Extra Credit

The following are worth extra credit points:

  1. Complete the assignment using pair programming. (1 point)
  2. Change the display of the word "zeros" such that the word "zero" is displayed if one zero is entered and "zeros" is displayed if 0 or more than 2 zeros are entered. Add this function to the same file as the rest of the program. (1 point)
You entered 1 even number, including 0 zeros, and 1 odd number

Make certain that your README.txt file describes any extra credit attempted.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.

Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the course information page.

Program Compilation

  • 4: Source code compiles with no errors or warnings
  • 2: Source code compiles with warnings
  • 0: Does not compile or wrong file turned in

Functionality

  • 10: Demonstrates mastery of the assignment
    • Has extra features or demonstrates techniques beyond the assignment
    • Applies concepts from the lesson(s) appropriately
    • Meets all specifications (see above) with particularly elegant solutions
    • Runs to completion with no abnormal error conditions
    • Generates correct output given correct input
    • Behaves in a reasonable way in response to incorrect data
    • Code is organized well into functions
  • 8: Has all the functionality expected of the assignment
    • Demonstrates many techniques from the lesson
    • Meets all specifications (see above)
    • Implementation seems more complicated than necessary.
    • May have one minor error
    • All test cases pass
  • 6: Has most of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets all but one of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have 2-3 minor errors
    • All but one test case passes
  • 4: Has some of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets at least 1/2 of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have more than 3 minor errors
    • At least 1/2 of all test cases pass
  • 2: Serious functional problems but shows some effort and understanding
    • Meets less than 1/2 of the of the specifications (see above)
    • Has a major error or many minor errors
    • Implementation seems very convoluted
    • Demonstrates few techniques from the lesson
    • Less than 1/2 of all test cases pass
  • 0: Does not execute or no specifications met

Programming Style

  • 4: Code is well-documented
  • 3: Code has minor documentation errors
    • Has 1 documentation error
  • 2: Code has some documentation errors
    • Has 2-3 documentation errors
  • 1: Code has many documentation errors
    • Has more than 3 documentation errors
  • 0: No apparent attempt to document code

REAME.txt File

  • 2: README.txt file submitted with specified information included
  • 1: README.txt submitted but some information was not included
  • 0: No README.txt submitted

Maximum Score: 20, plus extra credit

What to Turn In

Submit your assignment following the instructions for homework. Include the following items for grading:

  1. README.txt file
  2. classifier.cpp

You must submit all the files needed to make your assignment function properly. Your assignment must work as submitted.

Home | Blackboard | Announcements | Day Schedule | Eve Schedule
Course info | Help | FAQ's | HowTo's | Links

Last Updated: February 10 2007 @18:19:25