Question: Problem description - C + + program query Most products now sold are assigned a code which uniquely identifies the product. The ACME Company uses

Problem description- C++ program query
Most products now sold are assigned a code which uniquely identifies the product. The ACME Company uses a 10 digit product number that is normally a sequence of 10 decimal digits, but in some cases, the capital 'A' may also appear as the tenth digit. Hyphens may be included at various places in the product number to make them easier to read, but have no other significance. The sample input and expected output shown below illustrate many valid, and a few invalid, forms for product numbers.
Actually, only the first nine digits in a product number are used to identify a product. The tenth character serves as a checksum to verify that the preceding digits are correctly formed. This checksum is selected so that the value computed as shown in the following algorithm is evenly divisible by 11.
A checksum is important because it allows for the quick detection of errors when entering or transmitting data, reducing the risk of errors going unnoticed and resulting in incorrect or invalid data.
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 many), 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 sum2 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 sum2, makes the total sum evenly divisible by 11.
An example will clarify the procedure. Consider the (correct) product number 013-162-959-A. First look at the calculation of sum1:
digits in the product number 01316295910(A)
sum1
(partial sums)0145111322273646
sum2
(running totals)0151021345683119165
The calculation of sum2 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 sum1 and sum2 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.
All other characters that are not digits (0-9), hyphens (-), or the capital letter 'A' are considered illegal characters for a product number in this problem.
Output specification
For each candidate product number, print "Case N: "(where N is a 1-based count of product numbers analyzed), then:
If the product number is valid, it should be displayed in normalized form, e.g.,999-999-999-A, followed by "is correct"
The output format pattern "999-999-999" represents 3 sections of three-digit numbers, while the "A" section represents a single digit character or the letter 'A' if the checksum is 10.
If the product number is invalid, "incorrect product number" should be displayed.
Sample input (pa07-input0.txt)

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!