On This Page
Overview
There are three parts to this assignment:
- Review Exercises:
First make sure you have completed and turned in the exercises from lesson 6. Then complete the exercises in CodeLab 6. These exercises will help prepare you for the problem-solving program and should be completed first. You can look at solutions if you miss your first attempt.
- Problem Solving Program:
Complete the programming project following the Program Specifications listed below. You may make extra credit additions to this program as outlined in the section on Extra Credit.
- Tutorial Exercises:
Complete the Tutorial Exercises in CodeLab 6 for this assignment before the specified due date. Refer to the assigned reading for the next lesson to help you understand the problems. Also, you can use the online lecture notes for more information as the notes become available.
^ top
Background Information for Program
To sort letters more quickly, the United States Postal Service encourages companies to add a bar code to large volume mailings. One such bar code format is POSTNET "A" which encodes the five digit zip code of the address. The following is an example of a POSTNET A five-digit bar code (from Wikipedia).
POSTNET A bar codes are made up of long and short bars as shown in the diagram below. The diagram also shows the psuedo-binary encoding scheme you can use to decode bars. For example, the number 10100 is 1 x 7 + 0 x 4 + 1 x 2 + 0 x 1 + 0 x 0 = 9. The only exception to the coding scheme is 0, which is encoded as 11 according to the formula.
The layout of a five-digit zip code is shown below. Each side has a full-height frame bar. Inside the frame bars are the five encoded digits followed by a check digit. The check digit is computed by adding up all five digits of the zip code. The check digit is the smallest number you need to add to the sum to make the entire code a multiple of 10. For example, the code 91801 adds up to 19, so the check digit is 1 to make the sum equal to 20.
More Information
^ top
Program Specifications
Note that you must complete this program either by yourself or by working with one other student of this class following the rules of Pair Programming for Homework Assignments.
- Write a program that asks the user for a zip code and prints the POSTNET A bar code to the console.
Be sure to include the frame bars and check digit in the bar code displayed.
- Use a vertical bar '
|' for full bars and a comma ',' for half bars. For example, 95003 (Cabrillo's zip code) becomes:
||,|,,,|,|,||,,,||,,,,,||,,,||,|
- Within your program, define the two functions described by the comments and prototypes shown below:
/**
Creates a POSTNET "A" bar code for a ZIP code.
@param zip the code to convert to a barcode.
@return a bar code of the zip using "|" as the long
bar and "," as the half bar.
*/
string barcode(int zip);
/**
Encodes a single digit of a POSTNET "A" bar code.
@param digit the single integer digit to encode.
@return a bar code of the digit using "|" as the long
bar and "," as the half bar.
*/
string encode(int digit);
You may change the parameters, but do NOT change the functions names or return types.
- Your program must define between three and seven functions, including
main(), and call all the defined functions at least one time.
- Structure your code such that you declare function prototypes before
main() and function definitions after main() for all your functions.
- Remember to include one file comment block, a function comment block for all function prototypes, and follow all the other style rules we have covered so far.
- The name of the source code file must be
postal.cpp and all your code must be in this file.
Be careful of the spelling, including capitalization, as you will lose points for a misspelled name.
- Your program must follow the same sequence of operations as the example program including:
- No extra inputs other than entering a zip code
- Using 0 as a sentinel to exit the program
- Submit your files to Blackboard as explained in the section of this document: What to Turn In.
Example Program
You can see an example of how the program operates by downloading and running the executable file: postal.exe.
Hints
- Remember that we write functions for two reasons:
- To organize our code into modules
- To reduce repeated code
Thus, you do not want to write 10 different functions to create 10 different bar codes. All these functions work the same way. Instead, you want to write one function to create a bar code from a digit and call the function as many times as needed. For example:
/**
Encodes a single digit of a POSTNET "A" bar code.
@param digit the single digit to encode.
@return a bar code of the digit using "|" as the long
bar and "," as the half bar.
*/
string encode(int digit);
- We have covered two ways to extract digits from a single input and worked with them in class:
- Using the modulus operator in exercise 6.1
- Using strings and converting the strings to characters and digits in exercise 6.2
You may use either technique.
- Once you extract and encode a digit as a string, you need to arrange the barcode digits in the correct order. One way is to build a barcode one digit at a time, appending each new digit to the front or back of the barcode. Appending to the front lets you reverse the order. For more information on appending strings, see lesson 3.2.3: Joining Strings (Concatenation).
^ top
Extra Credit
The following are worth extra credit points:
- Complete the assignment using pair programming. (1 point)
- Write a second program that displays actual bars in a graphics window. (2 points)
- Write two functions:
halfBar() and fullBar() with any parameters you need
- The name of your second source code file must be
postalbars.cpp and all your code must be in this file.
Make certain that your README.txt file describes any extra credit attempted.
^ top
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.
Lesson Exercises
- 2: All lesson exercises attempted and turned in
- 1: Some lesson exercises completed and turned in
- 0: No lesson exercises completed or turned in
Program Compilation
- 4: Source code compiles with no errors or warnings
- 3: Source code compiles with 1 warning
- 2: Source code compiles with 2 warnings
- 1: Source code compiles with 3+ warnings
- 0: Does not compile or wrong file turned in
Functionality
- 10: Demonstrates mastery of the assignment
- Applies concepts from the lessons 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
- 8: Has all the functionality expected of the assignment
- Demonstrates many techniques from the lesson
- Attempts to meet all specifications (see above)
- Implementation seems more complicated than necessary.
- May have one minor error
- 6: Has most of the functionality expected of the assignment
- Demonstrates some techniques from the lesson
- Attempts to meet all but one of the specifications (see above)
- Implementation seems excessively complicated.
- May have 2-3 minor errors
- 4: Has some of the functionality expected of the assignment
- Demonstrates some techniques from the lesson
- Attempts to meet at least 1/2 of the specifications (see above)
- Implementation seems excessively complicated.
- May have more than 3 minor errors
- 2: Serious functional problems but shows some effort and understanding
- Attempts to meet 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
- 0: Does not execute
Program Style
- 4: Code is well-documented including:
- Name, date, and program description in file comment block
- Follows specified format for file comment block
- Has a function comment block for all function declarations following the specified format
- Proper use of spaces around operators
- No tab characters are present in the source code
- As described in How To Document and Organize C++ Code
- Correct file name used
- 3: Code has a minor documentation error
- 2: Code has some documentation errors
- 1: Code has many documentation errors
- 0: No apparent attempt to follow documentation standards or write documentation comments
CodeLab Exercises
Number completed correctly / number exercises * 8 and rounded up to the nearest integer.
README.txt File
- 2:
README.txt file submitted following the instructions
- 1:
README.txt file submitted but some information was missing
- 0: No
README.txt file submitted
Total possible: 30, plus extra credit
^ top
What to Turn In
Submit your assignment to Blackboard, in the assignment folder that matches the name of this assignment, following the instructions for submitting homework. Include the following items for grading:
README.txt file
- All the exercise files from Lesson 6
postal.cpp
- Optionally,
postalbars.cpp (extra credit)
You must submit all the files needed to complete your assignment. Your assignment must work as submitted.
You may assume that I have the turtle and graphics classes we discussed in class and you do not need to turn in the source code for those classes.
^ top
Home
| Blackboard
| Announcements
| Day Schedule
| Eve Schedule
Course info
| Help
| FAQ's
| HowTo's
| Links
Last Updated: April 21 2009 @14:17:49
|