In c++ please!
F or faster sorting of letters, the United States Postal Service encourages companies that send large volumes of mail to use a bar code denoting the zip code: CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE ECRLOT ** C057 CA 95014-5143 Hladıdll....llıdakıll.lllabollbald 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 add- ing up all digits, and choose a check digit to make the sum a multiple of 10. Frame bars CO57 • For example, the number 95014 has a sum of 19, so the check digit is 1 to make the sum equal to 20. ...... ..... ..... ..... ..... Digit 1 Digit 2 Digit 3 Digit 4 Digit 5 ...... Check Digit Encoding for Five-Digit Bar Codes
Each digit of the zip code, and the check digit, is encoded according to the following table where O denotes a half bar and 1 a full bar. Digit 1 2 3 4 5 6 7 8 9 Bar 1 Bar 2 (weight 7) (weight 4) 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 Bar 3 (weight 2) 0 1 1 0 0 1 0 0 1 Bar 5 Bar 4 (weight 1) (weight 0) 1 0 1 O 1 0 0 1 0 1 0 1 0 0 1 0 0 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. zip) which calculates the check digit according to the • int checkDigit(int 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 re- turn value. Finally, calculate and encode the check digit, surround the entire code with the frame bars, and return it. Here are the steps to solve this problem: 1. Write and document the prototypes the header file. Add header guards. 2. Stub out your functions in the implementation file. 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).
A Few Hints • codeForDigit() works great with just a switch. • For checkDigit(), use a limit loop 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. Use make test to test your code or make run to run any student tests. Once your score is OK, use make submit to turn it in.
In c++ please!
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am