Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

European countries uses a 13-digit code know as European Article Number (EAN) instead of the 12 digit Universal Product Code (UPC) found in North America.

European countries uses a 13-digit code know as European Article Number (EAN) instead of the 12 digit Universal Product Code (UPC) found in North America. Each EAN ends with a check digit, just as a UPC does. The technique for calculating the check digit is also similar:

Add the second, fourth, sixth, eighth , tenth, and twelfth digits.

Add the first, third, fifth, seventh, ninth, and eleventh digits.

Multiply the first sum by 3 and add it to the second sum.

Subtract one from the total.

Compute the remainder when the adjusted total is divided 10.

Subtract the remainder from 9.

For example, consider Gulluoglu Turkish Delight Pistachio & Coconut, which has an EAN of 8691484260008. The first sum is 6 + 1 + 8 + 2 + 0 + 0 = 17, and the second sum is 8 + 9 + 4 + 4 + 6 + 0 = 31. Multiply the first sum by 3 and adding the second sum yields 82. Subtracting 1 gives 81. The remainder upon dividing by 10 is 1. When the remainder is subtracted from 9, the result is 8, which matches the last digit of the original code. Your job is is modify the upc.c program (from KingsSourceCodes) so that it calculate the check digit for an EAN. Your tasks are:

1. Write a function, build12Digits(), that will create 12 random digits (0-9) and store them into an integer array. Put 0 into the 13th element for the initial check code. The function prototype for build12Digits() is as the following: void build12Digits(int [], int); /* the first parameter is an integer array and second parameter is an integer which is the size of the array) */

2. Write a function, printEANCode(), that will print the entire EAN codes (13 digits). The function prototype is: void printEANCode(int [], int); /* the first parameter is an integer array and second parameter is an integer which is the size of the array)*/

3. Write a function, calculateCheckDigit(), which will calculate the correct check digits and set it to the 13th element in the array.

The function prototype is: void calculateCheckDigit(int [], int); /* the first parameter is an integer array and second parameter is an integer which is the size of the array)*/

4. Modify the main() function as the following:

Declare an integer array with 13 entries. The size can be define as a constant.

Call build12Digits() function [2]

Call printEANCodes() function so that it looks like a normal EAN, but the check digit is 0. (example: 8 691484 26000 0). Please label this output as the incorrect check digit before the calculation.

Call calculateCheckDigit() function to calculate and store the correct check digit

Call printEANCodes() function so that it looks like a normal EAN, but the check digit is 0. (example: 8 691484 26000 8). Please label this output as the correct check digit after the EAN calculation.

Write the opening comment section including a detail program description of your code.

Check for correct indentations.

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

More Books

Students also viewed these Databases questions