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".

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
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).
07940080 4 5 0 1
0 24000162 8 60
011110856 8 07
05100013 8101
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 10 0 0 1 3 8 1 0 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). 07940080 4 5 0 1 0 24000162 8 60 011110856 8 07 05100013 8101 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 10 0 0 1 3 8 1 0 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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Array
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education