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:
For this
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.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
C How to Program (8th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
Absolute Java (6th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Computer Science: An Overview (12th Edition)
- write a program in python Write a program that will allow a student to enter their name and then ask them to solve 10 mathematical equations. The program should display two random numbers that are to be added, such as: 247 + 129 The program should allow the student to enter the answer. The program should then display whether their answer was right or wrong, and accumulate the right values. After the 10 questions are asked, calculate the average that was correct. Then display the student name, the number correct, and the average correct in both decimal and percentage format. In addition to any system functions you may use, you might consider the following functions: A function that allows the student to enter their name. A function that gets two random numbers, anywhere from 1 to 500. A function that displays the equation and asks the user to enter their answer. A function that checks to see if the answer is correct and accumulates the number correct. A function that calculates the…arrow_forwardIn python language, including print(song)arrow_forwardUsing, HTML,CSS , and javascript Write a program that takes as input the speed of a car e.g 80. If the speed is less than 70, it should print “Ok”. Otherwise, for every 5 km/s above the speed limit (70), it should give the driver one demerit point and print the total number of demerit points. For example, if the speed is 80, it should print: “Points: 2”. If the driver gets more than 12 points, the function should print: “License suspended”.arrow_forward
- A program has a string variable fullName that stores a first name, followed by a space, followed by a last name. There are no spaces in either the first or last names. Here are some examples of fullName values: "Anthony Coppola", "Jimmy Carroll", and "Tom DeWire". Consider this code segment that extracts the last name from a fullName variable, and stores it in last Name with no surrounding blanks: int k = fullName.indexOf(" "); //find index of blank String lastName = /* expression */ Which is a correct replacement for /* expression */? II fullName.substring(k + 1); III fullName.substring(k + 1, fullName.length());arrow_forwardMany documents use a specific format for a person's name. Using string objects, not vectors nor C-strings, write a program whose input is: firstName middleName lastName and whose output is: lastName, firstInitial.middlelnitial. Ex: If the input is: Pat Silly Doe the output is: Doe, P.S. If the input has the form: firstName lastName the output is: lastName, firstInitial. Ex: If the input is: Julia Clark the output is: clark, J. 448070.3207206.qx3zqy7 LAB ACTIVITY 9.11.1: LAB: Chapman Name format 1 #include 2 #include 3 using namespace std; 4 int main() { 5 /* Type your code here. */ 6 7 return 0; 01 main.cpp 0/10 Load default template...arrow_forwardCreate an application that generates a histogram so you can examine the frequency distribution of a collection of values visually. A random number of integers between 1 and 100 inclusive should be entered into the programme. After that, it should generate a chart like the one below, showing how many input values went between 1 and 10, 11 to 20, and so on.For each number entered, print one asterisk. 1 - 10 | ***** 11 - 20 | ** 21 - 30 | ******************* 31 - 40 | 41 - 50 | *** 51 - 60 | ******** 61 - 70 | ** 71 - 80 | ***** 81 - 90 | ******* 91 – 100 | ********arrow_forward
- The Research team led by Bernadette Wolowitz at Cal-tech University has discovered a new Amoeba that grows in the order of a Fibonacci series every month. They are exhibiting this amoeba in a national. conference. They want to know the size of the amoeba at a particular time instant. If a particular month's index is given, write a program to display the amoeba's size. For Example, the size of the amoeba on month 1, 2, 3, 4, 5, 6,... will be 0, 1, 1, 2, 3, 5, 8.... respectively.arrow_forwardJava with out string formarrow_forwardWrite a program that asks the user to enter an account number as a string. The account number consists of 8 characters and is divided as follows: The first 2 characters are digits and represent the branch (00 for Beirut, 01 for Saida, 02 for Tripoli). • The remaining 6 characters represent the customer's account number A valid account number consists of exactly 8 characters. If the account is valid, the program prints the details (branch and account number). If the account is not valid, the program displays a message to the user. Sample Run 1: Enter a string: 100201 Not valid //It is not valid because the string is not composed of 8 characters Sample Run 2: Enter a string: AB100201 Not valid //It is not valid because the branch is wrong Sample Run 3: Enter a string: 00100201 Branch: Beirut Customer number: 100201 Sample Run 4: Enter a string: 0210AB01 Branch: Tripoli Customer number: 10AB01arrow_forward
- Write a code in python that takes a number originally formatted as a string, divides it by the length of the original string, and returns the result Take a number originally formatted as a string, Then divide it by the length of the original string. Arguments: ‘number_a_string’: A number, only that it is formatted as a string. For instance: Instead of passing 15, you pass “15” (surrounded by quotation marks) Output: ‘result’ : A number Example: If you call number_gymnastics(“14”), The output should be the number 7.0, because 14 divided by 2 (the length of the “14” string) is equal to the number 7.0arrow_forwardA contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes in word pairs that consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Ex: If the input is: Joe 123-5432 Linda 983-4123 Frank 867-5309 Frank the output is: 867-5309 LAB 6.21.1: LAB: Contact list 0/ 10 ACTIVITY main.py Load default template... 1 user_input = input() 2 entries = user_input.split() 3 contact_list = dict(pair. split(':') for pair in entries)arrow_forwardCODE THIS USING PYTHON THANKSarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education