The US Postal Services uses bar codes to represent zip codes in order to sort them...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The US Postal Services uses bar codes to represent zip codes in order to sort them quickly using machines. The machine will read the bar code and direct the letter to the right location. Write a C++ program that generate bar codes. The program should read the zip code and determines the complete bar code. The code is represented by a series of short and long bars. The following table shows the barcodes for each digit. Value Encoding 1 2 3 4 5 lal G illu 7 8. Inh 9 Th 0 Use and 'I' to represent short and long bars. A check digit is also added at the end of the barcode. The check digit is determined by totaling all the digits of the zip code and adding a digit that makes the sum divisible by 10. For example, if the sum of all the digits is 38 then the check digit is 2, if the sum is 40 the check digit is 0, etc. A long bar is added at the beginning and at the end of the barcode (total of 32 bars). The following is an example of the code 45701 (sum = 17, check digit is 3) 4 5 7 0 1 3 Check Digit Your program should generate the codes repeatedly until the user decided to quit. Your program should print an error message if the zip code entered is invalid (for example, non-digit character, fewer or more than 5 digits). Your program must include at least the following two functions (do not change the names or the prototypes): string getDigitCode (char digit): return a barcode for a single digit int getCheckDigitValue (int sum): return the check digit You are encouraged to add other functions. Sample Run: Enter a zip code: 45701 Code: 1:1:1:1:1: More codes (y/n)? y Enter a zip code: 456 Error: zip code must be 5 digits More codes (y/n)? y Enter a zip code: 56-45 Error: Code is invalid More codes (y/n)? y Enter a zip code: 564565 Error: Code is invalid More codes (y/n)? y Enter a zip code: 12345 Code: :::||::|:|::|::|::|::|:1:1 More codes (y/n)? n Grading: Programs that contain syntax errors will earn zero points. Programs that do not include functions other than main, will also earn zero points. Programs that use global variables other than constants, will earn zero points. Programs that use libraries NOT discussed in class will earn zero points. Your grade will be determine using the following criteria: . Correctness: the program works as requested above (35 points). (5 points) The code is printed correctly (32 bars) o (20 Points) The required functions are implemented o (10 points) Error checking The US Postal Services uses bar codes to represent zip codes in order to sort them quickly using machines. The machine will read the bar code and direct the letter to the right location. Write a C++ program that generate bar codes. The program should read the zip code and determines the complete bar code. The code is represented by a series of short and long bars. The following table shows the barcodes for each digit. Value Encoding 1 2 3 4 5 lal G illu 7 8. Inh 9 Th 0 Use and 'I' to represent short and long bars. A check digit is also added at the end of the barcode. The check digit is determined by totaling all the digits of the zip code and adding a digit that makes the sum divisible by 10. For example, if the sum of all the digits is 38 then the check digit is 2, if the sum is 40 the check digit is 0, etc. A long bar is added at the beginning and at the end of the barcode (total of 32 bars). The following is an example of the code 45701 (sum = 17, check digit is 3) 4 5 7 0 1 3 Check Digit Your program should generate the codes repeatedly until the user decided to quit. Your program should print an error message if the zip code entered is invalid (for example, non-digit character, fewer or more than 5 digits). Your program must include at least the following two functions (do not change the names or the prototypes): string getDigitCode (char digit): return a barcode for a single digit int getCheckDigitValue (int sum): return the check digit You are encouraged to add other functions. Sample Run: Enter a zip code: 45701 Code: 1:1:1:1:1: More codes (y/n)? y Enter a zip code: 456 Error: zip code must be 5 digits More codes (y/n)? y Enter a zip code: 56-45 Error: Code is invalid More codes (y/n)? y Enter a zip code: 564565 Error: Code is invalid More codes (y/n)? y Enter a zip code: 12345 Code: :::||::|:|::|::|::|::|:1:1 More codes (y/n)? n Grading: Programs that contain syntax errors will earn zero points. Programs that do not include functions other than main, will also earn zero points. Programs that use global variables other than constants, will earn zero points. Programs that use libraries NOT discussed in class will earn zero points. Your grade will be determine using the following criteria: . Correctness: the program works as requested above (35 points). (5 points) The code is printed correctly (32 bars) o (20 Points) The required functions are implemented o (10 points) Error checking
Expert Answer:
Related Book For
Discovering Advanced Algebra An Investigative Approach
ISBN: 978-1559539845
1st edition
Authors: Jerald Murdock, Ellen Kamischke, Eric Kamischke
Posted Date:
Students also viewed these programming questions
-
Kimiko signed a loan agreement requiring payments of $234.60 at the end of every month for six years at 7.2% compounded monthly. (a) How much was the original loan balance? (b) If Kimiko missed the...
-
Folders Office Supply makes two types of paper pads, legal and regular. A box of legal pads requires 20 minutes to produce and a box of regular pads requires 10 minutes to produce. Two people work on...
-
The growth of accrued interest takes place independently of changes in the interest rate environment. Do you agree or disagree with this statement? Explain your reasoning.
-
a. Calculate the initial investment associated with each of Clark Upholsterys alternatives. b. Calculate the incremental operating cash inflows associated with each of Clarks alternatives. c....
-
Each cord can sustain a maximum tension of 400 N. (Figure 1) Part A Figure B 60 A H 1 of 1 Determine the largest mass of pipe that can be supported. Express your answer to three significant figures...
-
Tolden Trading has borrowed from MacBank to invest in a project. The loan requires a repayment of $17,384 at the end of every month for three years. The lender quoted Tolden Trading a rate of 8.40...
-
Find the floor value of key that is inside a BST.
-
The following vector field is given: \(\mathbf{A}=\frac{1}{2} x^{2} \hat{\mathbf{i}}-x y \hat{\mathbf{j}}+x y z \hat{\mathbf{k}}\). Check whether the field is irrotational.
-
A rectangular slab of the same size and arranged in the same way as that in the question 4 has a surface density that varies with position according to the function \(\sigma(x, y)=a_{0}+a_{1} x y\)...
-
An ideal spring that is initially compressed is released at the initial time to throw an object of mass \(m=60 \mathrm{~g}\) upward. The body reaches a height \(h=2.0 \mathrm{~m}\) from its initial...
-
The vector field of the question 6 is given. Determine the value of its divergence at the point \(\mathrm{P}\) of Cartesian coordinates \((2,4,3)\). Question 6 The following vector field is given:...
-
Listen to this video about the top 10 supply chain innovations of all times (http://www.youtube.com/watch?v=Mja5PM-CNkU). What do you think will be the next supply chain innovation to be ranked among...
-
Explain the buyers position in a typical negotiation for a business. Explain the sellers position. What tips would you offer a buyer about to begin negotiating the purchase of a business?
-
Calculate the stresses in the bar shown in Fig. 13.67. if its temperature is raised by \(40^{\circ}\) C. \(E_{s}=2 E_{c}=200 \mathrm{GPa}, \alpha_{s}=12.5 \times 10^{-6} \mathrm{per}^{\circ}...
-
Two rods are joined together one behind the other and the extreme ends are built in the fixed supports. One rod is of steel \(3 \mathrm{~m}\) long and \(600 \mathrm{~mm}^{2}\) cross-sectional area....
-
A steel bar of 25 mm diameter is loaded as shown in Fig. 13.12 (a). Calculate the stress in each portion and the total elongation. Take \(E=200 \mathrm{GPa}\). B 30 kN 20 kN C D 15 kN -200mm 100 -300...
Study smarter with the SolutionInn App