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 digit product number that is normally a sequence of 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
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 to guarantee divisibility by and the representation of the number requires digits to many a special symbol was selected by Acme Company to represent and that is the role played by A
The algorithm used to check a product number is relatively simple. Two sums, sum and sum are computed over the digits of the product number, with sum being the sum of the partial sums in sum after each digit of the product number is added to it The checksum is the value that, when added to sum makes the total sum evenly divisible by
An example will clarify the procedure. Consider the correct product number A First look at the calculation of sum:
digits in the product number A
sum
partial sums
sum
running totals
The calculation of sum is done by computing the total of the partial sums in the calculation of sum
We now verify the correctness of the product number by noting that is indeed, evenly divisible by
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 nondigit characters dont 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 and sum sums, as described in the problem statement.
Check if the sum sum is divisible by 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 andor followed by additional spaces. No line will contain more than 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 : 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
All other characters that are not digits 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 based count of product numbers analyzed then:
If the product number is valid, it should be displayed in normalized form, egA followed by is correct"
The output format pattern represents sections of threedigit numbers, while the A section represents a single digit character or the letter A if the checksum is
If the product number is invalid, "incorrect product number" should be displayed.
Sample input painputtxt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
