A barcode scanner for Universal Product Codes (UPCs) verifies the 12-digit code comparing the code's largest digit (called a check digit) to its own computation from the first 11 digits as follows: 1. Calculate the sum of the digits in the odd-numbered positions (the first, third digits) and multiply this sum by 3. 2. Calculate the sum of the digits in the even-numbered position (the second, fo digits) and add this to the previous result. 3. If the last digit of the result from step 2 is 0, then 0 is the check digit. Otherw the last digit from 10 to calculate the check digit.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
A barcode scanner for Universal Product Codes (UPCs) verifies the 12-digit code scanned by
comparing the code's largest digit (called a check digit) to its own computation of the check digit
from the first 11 digits as follows:
1. Calculate the sum of the digits in the odd-numbered positions (the first, third,..... eleventh
digits) and multiply this sum by 3.
2. Calculate the sum of the digits in the even-numbered position (the second, fourth....tenth
digits) and add this to the previous result.
3. If the last digit of the result from step 2 is 0, then 0 is the check digit. Otherwise, subtract
the last digit from 10 to calculate the check digit.
4. If the check digit matches the final digit of the 12-digit UPC, the UPC is assumed correct
By using C++ write a program that prompts the user to enter the 12 digits of a barcode separated by
space.
The program should store the digits in an integer array, calculate the check digit, and compare it
to the final barcode digit. If the digits match, output the barcode with the message "validated".
If not, output the barcode with the message "error in barcode".
Also output with labels the results from step 1 and 2 of the check-digit calculations. Note that the
"first" digit of the barcode will be store in element 0 of the array. Try your program on the
following barcodes, three of which are valid. For the first barcode, the result from step 2 is 79 (0
+9+0+8+4+0) * 3+ (7+4+0+0+5).
079400804501
024000162860
011110856807
051000138101
Noted that you need to include the below function:
void calculateTotal(unsigned int [], unsigned int&, unsigned int& );
SAMPLE RUN:
Enter 12 integers separated by blanks or <return>S:
0 5 1 0 0 0 1 3 8 10 1
The sum of the digits in the odd-numbered positions: 10
The sum of the digits in the even-numbered positions: 9
The sum of the digits in the even-numbered positions and oddnumbered positions: 39
Entered Barcode:
051000138101
Result: Validated Barcode !
Transcribed Image Text:A barcode scanner for Universal Product Codes (UPCs) verifies the 12-digit code scanned by comparing the code's largest digit (called a check digit) to its own computation of the check digit from the first 11 digits as follows: 1. Calculate the sum of the digits in the odd-numbered positions (the first, third,..... eleventh digits) and multiply this sum by 3. 2. Calculate the sum of the digits in the even-numbered position (the second, fourth....tenth digits) and add this to the previous result. 3. If the last digit of the result from step 2 is 0, then 0 is the check digit. Otherwise, subtract the last digit from 10 to calculate the check digit. 4. If the check digit matches the final digit of the 12-digit UPC, the UPC is assumed correct By using C++ write a program that prompts the user to enter the 12 digits of a barcode separated by space. The program should store the digits in an integer array, calculate the check digit, and compare it to the final barcode digit. If the digits match, output the barcode with the message "validated". If not, output the barcode with the message "error in barcode". Also output with labels the results from step 1 and 2 of the check-digit calculations. Note that the "first" digit of the barcode will be store in element 0 of the array. Try your program on the following barcodes, three of which are valid. For the first barcode, the result from step 2 is 79 (0 +9+0+8+4+0) * 3+ (7+4+0+0+5). 079400804501 024000162860 011110856807 051000138101 Noted that you need to include the below function: void calculateTotal(unsigned int [], unsigned int&, unsigned int& ); SAMPLE RUN: Enter 12 integers separated by blanks or <return>S: 0 5 1 0 0 0 1 3 8 10 1 The sum of the digits in the odd-numbered positions: 10 The sum of the digits in the even-numbered positions: 9 The sum of the digits in the even-numbered positions and oddnumbered positions: 39 Entered Barcode: 051000138101 Result: Validated Barcode !
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY