| Date Assigned: | Tue Jan-30 |
| Date Due: | Wed Jan-31 |
To demonstrate some real-world uses of your computer expertise, this assignment deals with real-world UPC codes. UPC codes are the numbers under the bar codes on virtually every product in every store these days. Together with bar codes, they are what allow your happy checkout clerk to automagically enter the price of your purchases merely by scanning those products.
UPC codes also have a check-digit included in them. This digit is computed based upon the other digits. For those of you who can recall last semester still, while this is not exactly the same as a parity bit, it is much in the same spirit. The point is: if somehow the UPC code is corrupted (say, because the scanner has a smudge on it and so reads a "7" as a "2" -- oops!), the check-digit should usually detect this and do something reasonable (like set off loud alarms or perhaps just opt for the Blue Screen of Death, something like that).
How do you compute a UPC check-digit? Easy. Check out http://grover.mta.ca/upc/check.html, or any other web site which explains the matter.
Your assignment: write a program which repeatedly reads in 12-digit UPC codes, and outputs "VALID" if it the check-digit test passes, and "INVALID!!!" otherwise. Also, if instead of a digit, the first character of the UPC code is the letter 'q' (for quit), then you should quit (without reading any further characters).
Hint: you may not read the UPC code in as an integer, because 12-digit integers would overflow. So instead you must read in the 12 digits as characters. (Actually, you would have to read it as a character anyhow, because the first character may be either a digit or the letter 'q' to quit.)
Second hint: You do not need to store these characters in a vector -- just compute as you go along.
Good luck!
DK