Question: In C + + - Since the checksum may sometimes need to be as large as 1 0 to guarantee divisibility by 1 1 ,

In C++-Since the checksum may sometimes need to be as large as 10 to guarantee divisibility by 11, and the representation
of the number 10 requires 2 digits (1 to mamy), a special symbol was selected by Acme Company to represent 10, and
that is the role played by 'A:
The algorithm used to check a product number is relatively simple. Two sums, sum1 and sum2, are computed over the
digits of the product number, with sum 2 being the sum of the partial sums in sum1 after each digit of the product
number is added to it. The checksum is the value that, when added to sum 2, makes the total sum evenly divisible by
An example will clarify the procedure. Consider the (correct) product number 013-162-959-A. First look at the
calculation of sum1:
The calculation of sum 2 is done by computing the total of the partial sums in the calculation of sum1.
We now verify the correctness of the product number by noting that 165 is, indeed, evenly divisible by 11.
Steps
To solve this problem, you can follow these steps:
Read the input using input redirection "", one line at a time, and for each line, preprocess it by removing any non-
digit characters (don't forget 'A')
Check if the preprocessed input contains exactly ten characters, and if not, print "incorrect product number".
Validate the input by checking if the first nine characters are digits and the last character is either a digit or the
letter 'A:
Compute the sum 1 and sum 2 sums, as described in the problem statement.
Check if the sum2 sum is divisible by 11. If it is, print the product number in the normalized form, followed by "is
correct." Otherwise, print "incorrect product number."
Input specification
The input data for this problem will contain one candidate product number per line of input, perhaps preceded and/or
followed by additional spaces. No line will contain more than 80 characters, but the candidate product number may
contain illegal characters and more or fewer than the required ten digits. Valid product numbers may include hyphens
at arbitrary locations. The end of file marks the end of the input data.
In the context of this problem, legal characters for a product number are:
Digits (0-9): The first nine characters of a product number must be digits. These digits represent the actual
product identifier.
Hyphens (-): Hyphens may be included at various places in the product number to make them easier to read.
However, they have no other significance and can appear in arbitrary locations.
Capital 'A': The capital letter 'A' may appear as the tenth character in a product number, representing a checksum
value of 10.
In C + + - Since the checksum may sometimes need

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!