Wyo C++ |
Name - |
The check digit of a seven digit number is computed by first assigning each digit the factors 2 through 8, starting with the rightmost digit. Multiply each actual digit by its factor and keep the sum of those products. Divide the sum by 123. If the integer remainder is less than 10, then the remainder is the check digit. If it is not less than 10, then repeat the process using the previous sum of the products until a new integer remainder is less than 10. As a precondition, you can assume that seven-digit numbers that lead to a sum of 17 will never be used, since an infinite loop would result.
For example, if the seven-digit number is 7654321, the first sum is 168. When divided by 123, the remainder is 45. Since 45 is not less than 10, repeat the process using the sum 168. Assigning the factors of 2, 3, and 4 to the digits 8, 6, and 1, a new sum of 38 is found. When divided by 123, the remainder is 38. When the process is applied to 38, the sum is 25 and the remainder is 25. When the process is applied to 25, the next sum is 16 and the remainder is 16. When the process is applied to 16, the next sum is 15 and the remainder is 15. When the process is applied to 15, the next sum is 13 and 13 is the remainder. When the process is applied to 13, the sum is 9 and the remainder is 9. Therefore, the check digit of 7654321 is 9.
Your function must correlate with either one of the following function prototypes. Notice that the first prototype specifies that the seven-digit number is passed as an integer while the second receives the seven-digit number passed as a string.
int findCheckDigit(int);
int findCheckDigit(apstring);
Save your function along with a driver program that tests it into a file named ch9checkdigit.cpp and submit the hardcopy with your name including in a comment line at the top of the file. Staple your pseudocode to the hardcopy before handing them in to the instructor. There will be no main function in this file but you must include any necessary header files that are required by your function. You must create your own driver program to test the function if you are not sure of the code that you write.