Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Universal product codes are the familiar bar codes that identify products so that they can be automatically priced at the checkout counter. A UPC is

Universal product codes are the familiar bar codes that identify products so that they can be automatically priced at the checkout counter. A UPC is a 12-digit code in which the first digit characterizes the type of product (0 identifies an ordinary grocery item, 2 is an item sold by weight, 3 is a medical item, 4 is a special item, 5 is a coupon, and 6 and 7 are items not sold in retail stores). The next 5 digits identify the manufacturer, the next five digits identify the product, and the last digit is a check digit. (All UPC codes have a check digit. It is always present on the bar code, but it may not appear in the printed version.) For example, the UPC for a package of 10 Ortega taco shells is 0-54400-00800-5. The first zero indicates this is an ordinary grocery item, the next five digits 54400 identify the manufacturer Nabisco Foods, and the next five dights 00800 identify the product as a package of 10 Ortega taco shells. The check digit is computed as follows. First compute s, where s is 3 times the sum of every other number starting with the first plus the sum of the remaining numbers, starting with the second. The check digit is the number c, between 0 and 9 satisfying (c+s) mod 10 = 0. For the code on the package of taco shells, we would have ... 0-54400-00800-5 0 + 5 + 4 + 4 + 0 + 0 + 0 + 0 + 8 + 0 + 0 + 5 *3 *1 *3 *1 *3 *1 *3 *1 *3 *1 *3 *1 - - - - - - - - - - - - s = 0 + 5 +12 + 4 + 0 + 0 + 0 + 0 +24 + 0 + 0 + 5 = 50 Since 50 mod 10 = 0, the number has been read correctly. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following product has been scanned and the number is 0-54400-00800-5. See if it is valid. 0 - 5 4 4 0 0 - 0 0 8 0 0 - 5 x x x x x x x x x x x x 3 1 3 1 3 1 3 1 3 1 3 1 - - - - - - - - - - - - 0 5 12 4 0 0 0 0 24 0 0 5 = 50 50 is a multiple of 10, therefore we conclude that the number is ok - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - For this assignment you are to write a C++ program that will read in UPC numbers and check them for correctness. The data includes numbers that are ok, two numbers that are wrong, and a number that is scanned backwards. data to be used for input upc 9-10679-87078-4 upc 7-93190-02004-9 upc 0-41100-33077-2 upc 0-76281-70322-0 upc 0-41270-87455-4 upc 0-41270-88000-8 upc 0-41163-41030-5 upc 0-44300-12392-9 upc 0-36000-28590-1 upc 8-00088-07214-0 sample output upc 9-10679-87078-4 ok upc 7-93190-02004-9 ok upc 0-41100-33077-2 ok upc 0-76281-70322-0 ok upc 0-41270-87455-4 error upc 0-41270-88000-8 ok upc 0-41163-41030-5 ok upc 0-44300-12392-9 error upc 0-36000-28590-1 ok upc 8-00088-07214-0 ok - backwards Some Logic you may want to use: total = 0 multiplier = 3 loop 20 times incrementing i by 1 pick off the i'th character if the character is a digit then convert the character to a number total = total + number*multiplier change the multiplier end loop if the total is a multiple of ten then write 'ok' else do the same check as above but go through the loop backwards if the total is a multiple of ten then write 'ok - backwards' else write 'error' 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

What must a creditor do to become a secured party?

Answered: 1 week ago

Question

When should the last word in a title be capitalized?

Answered: 1 week ago