Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ language or faster sorting of letters, the United States Postal Service encourages compa- nies that send large volumes of mail to use a bar

C++ language

or faster sorting of letters, the United States Postal Service encourages compa- nies that send large volumes of mail to use a bar code denoting the zip code:

The encoding scheme for a five-digit zip code is shown below. There are full-height frame bars on each side. The five encoded digits are followed by a check digit, which is computed by adding up all digits, and choose a check digit to make the sum a multiple of 10. For example, the number 95014 has a sum of 19, so the check digit is 1 to make the sum equal to 20.

Each digit of the zip code, and the check digit, is encoded according to the following table where 0 denotes a half bar and 1 a full bar.

To solve this problem, write three functions (pay attention to the return types):

string codeForDigit(int digit) which takes one digit and returns the ap- propriate code for that digit, using the table above. Use ':' for the half-bars

and '|' for the full bars. int checkDigit(int zip) which calculates the check digit according to the rules shown above. string barCode(int zip) which returns an entire bar code by breaking the number into individual digits, encoding that digit, and adding it to the string return value. Finally, calculate and encode the check digit, surround the entire code with the frame bars, and return it. Run get-starters to upload the starter code to your workspace. Then: 1. Write and document your prototypes in h06.h. Don't forget header guards. 2. Stub out your functions in h06.cpp. Run make test to make sure you have the mechanics correct before going on. 3. Implement the codeForDigit() function first. Run the tests for that. 4. Calculate the checkDigit() function and run the tests for that. 5. Finally, write and test the barCode() function (which will be fairly short).

H O M E W O R K 6 G O I N G P O S T A L

A Few Hints codeForDigit() works great with just a switch. For checkDigit(), use a limit loop (last chapter) as well as the remainder operator to find the digit that gets the sum to the next multiple of 10. For barCode(), first calculate the check digit. Extract each digit using a limit loop and get its code; use the building-a-string pattern to add the code to the result. Finally, add the code for the check digit and the two frame bars.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Core Ios Developer S Cookbook Core Recipes For Programmers

Authors: Erica Sadun ,Rich Wardwell

5th Edition

0321948106, 978-0321948106

More Books

Students also viewed these Programming questions

Question

Find the derivative of the following functions. f(x) = xe -x

Answered: 1 week ago

Question

Help Tony write his job description. P-96

Answered: 1 week ago