bartleby

Videos

Textbook Question
Book Icon
Chapter 10, Problem 10PP

The U.S. Postal Service printed a bar code on every envelope that represented a five- (or more) digit zip code using a format called POSTNET (this format was deprecated in favor of a new system, OneCode, in 2009). The bar code consists of long and short bars as shown:Chapter 10, Problem 10PP, The U.S. Postal Service printed a bar code on every envelope that represented a five- (or more)

For this program, we will represent the bar code as a string of digits. The digit 1 represents a long bar, and the digit 0 represents a short bar.

Therefore, the bar code would be represented in our program as

110100101000101011000010011

The first and last digits of the bar code are always 1. Removing these leaves 25 digits. If these 25 digits are split into groups of 5 digits each, we have

10100 10100 01010 11000 01001

Next, consider each group of 5 digits. There will always be exactly two 1s in each group of digits. Each digit stands for a number. From left to right, the digits encode the values 7, 4, 2, 1, and 0. Multiply the corresponding value with the digit and compute the sum to get the final encoded digit for the zip code. The table below shows the encoding for 10100.

Bar Code Digits 1 0 1 0 0
Value 7 4 2 1 0
Product of Digit 4 Value
Zip Code Digit = 7 + 0 + 2 + 0 + 0 = 9

Repeat this for each group of 5 digits and concatenate to get the complete zip code. There is one special value. If the sum of a group of 5 digits is 11, then this represents the digit 0 (this is necessary because with two digits per group it is not possible to represent zero). The zip code for the sample bar code decodes to 99504. Although the POSTNET scheme may seem unnecessarily complex, its design allows machines to detect if errors have been made in scanning the zip code.

Write a zip code class that encodes and decodes 5-digit bar codes used by the U.S. Postal Service on envelopes. The class should have two constructors. The first constructor should input the zip code as an integer, and the second constructor should input the zip code as a bar code string consisting of 0s and 1s, as described above. Although you have two ways to input the zip code, internally, the class should store the zip code using only one format (you may choose to store it as a bar code string or as a zip code number). The class should also have at least two public member functions, one to return the zip code as an integer, and the other to return the zip code in bar code format as a string. All helper functions should be declared private. Embed your class definition in a suitable test program. Your program should print an error message if an invalid bar code is passed to the constructor.

Blurred answer
Students have asked these similar questions
Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: A, B, and C  2 D, E, and F  3 G, H, and I  4 J, K, and L  5 M, N, and O  6 P, Q, R, and S  7 T, U, and V  8 W, X, Y, and Z  9 Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD the application should display 555-438-3663. Gaddis Tony. Starting Out with Python (2-downloads) (p. 367). Pearson Education. Kindle Edition.
Our usual number system is base 10, because it strings together the digits 0 – 9 to form any whole number  (there is a 1’s place, a 10’s place, a 10-squared’s place, etc). Hexadecimal numbers are written in base  16. This means they string together the digits 0 – 9 and the letters A – F to form any whole number (there  is a 1’s place, a 16’s place, a 16-squared’s place, etc). For example, BD3C8 and 305A2 are two  different 5-digit hexadecimal numbers. How many 9-digit hexadecimal numbers are there that have  exactly 4 zeroes. (Note: Hexadecimal numbers, like our normal base 10 numbers, cannot start with a 0)
When we say arithmetic expression, we mean a kind of expression you can type in a very basic desk calculator. That is, neither variables nor brackets are allowed. It contains only numbers and four arithmetic operators, +, -, *, and /.   The following are some examples of arithmetic expression:   Any number string with or without signs - e.g. 3, -1, +10, 3.14, -0.70 and 099. Number strings mixed with arithmetic operators - e.g. 3+5, -1+2*3, 7/10-0.7, and -1.4-+8.2.   An example of FA diagram for recognising a non-negative integer is given below. You may use it as a start point. You need to add a few more states and transitions to handle numbers with decimal point and signs (e.g. -5, +2, 0.21, -32.6, +99.05, but not the form 1.0E-3). Most importantly, you also need to add a few more things to deal with the arithmetic operators +, -, *, /.

Chapter 10 Solutions

Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)

Ch. 10.2 - Below we have redefined the class DayOfYear from...Ch. 10.2 - Given the following class definition, write an...Ch. 10.2 - Prob. 13STECh. 10.2 - The private member function DayOfYear::checkDate...Ch. 10.2 - Suppose your program contains the following class...Ch. 10.2 - Suppose you change Self-Test Exercise 15 so that...Ch. 10.2 - Explain what public: and private: do in a class...Ch. 10.2 - a. How many public: sections are required in a...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Suppose your program contains the following class...Ch. 10.2 - How would you change the definition of the class...Ch. 10.2 - Prob. 24STECh. 10.3 - When you define an ADT as a C++ class, should you...Ch. 10.3 - When you define an ADT as a C++ class, what items...Ch. 10.3 - Suppose your friend defines an ADT as a C++ class...Ch. 10.3 - Redo the three- and two-parameter constructors in...Ch. 10.4 - How does inheritance support code reuse and make...Ch. 10.4 - Can a derived class directly access by name a...Ch. 10.4 - Suppose the class SportsCar is a derived class of...Ch. 10 - Solution to Practice Program 10.1 Redefine...Ch. 10 - Redo your definition of the class CDAccount from...Ch. 10 - Define a class for a type called CounterType. An...Ch. 10 - Write a grading program for a class with the...Ch. 10 - Redo Programming Project 1 (or do it for the first...Ch. 10 - Define a class called Month that is an abstract...Ch. 10 - Redefine the implementation of the class Month...Ch. 10 - My mother always took a little red counter to the...Ch. 10 - Write a rational number class. This problem will...Ch. 10 - Define a class called Odometer that will be used...Ch. 10 - Redo Programming Project 7 from Chapter 5 (or do...Ch. 10 - The U.S. Postal Service printed a bar code on...Ch. 10 - Consider a class Movie that contains information...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY