![]() ![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
CMPT 120: Assignment 1Part 1: Written - 25%Answer the following questions in a text file named assign1.txt.1. Convert these binary numbers into decimal assuming they are unsigned integers. Show your calculations.
a. 1001
2. Convert the same binary numbers into decimal assuming they are using signed magnitude representation. Show your calculations. b. 011011 c. 01011010 d. 10000000 3. Convert these binary numbers into decimal assuming they are using two's complement representation. Show your calculations. 4. Name the data types that the following expressions evaluate to in Python.
a. 21.0 * 4 - 123
b. 5 + 23 / 17 c. "34" + "2" d. (24 * 32) > (43 - 12) Part 2: Programming - 75%A program to compute the last digit of a barcodeIf you look on the back of the box/label of any commercial product, you will find a barcode which represents its product code. A product code is used to uniquely identify it (e.g. when you're at the grocery store, the cashier scans the barcode with his/her barcode reader and instantly knows which product you are buying and its price). ![]() Product codes vary in length from 8 to 18 digits. You may have heard of these product codes referred to as UPCs (Universal Product Codes), but UPCs are only one of the many flavours of product codes found on items we buy every day:
The last digit of every flavour of product code is a check digit used as a validity check. This lets the scanner check for errors in the scanning: if the check digit is right, it probably scanned correctly. The check digit is calculated by performing a calculation on the first n-1 digits of a n-digit product code.
Your programming task for this assignment will be to create a program which calculates the check digit for any of the different product codes listed above, given the first n-1 digits of a product code. Your program should be created in a file called The algorithm to implement check digit calculation for any length product code is the same. Let's assume the first 11 digits of a UPC-A code are “23139085377” and we would like to derive the check digit:
So, in the example, the check digit is 2. The whole UPC code for this product is "231390853772". Using the above described algorithm, create a program that:
Your program should interact with the user as follows:
Check Digit Calculator
-------------------- 1. EAN-8 2. UPC-A 3. EAN-13 4. EAN-14 5. SSCC -------------------- Choose your product code type: 2 Enter first 11 digits of your product code: 23139085377 -------------------- The check digit is 2. The product code is 231390853772.
Remember, your program should ask for the appropriate number of digits based on the type of product code for which a check digit is being calculated. For this, you'll need to use
Before you submit the program, check it with some products you have around. Determine the type of barcode from the number of digits; enter all but the last digit and make sure the check digit matches. (But see the last “hint” below.) Hints
When you're done, create a ZIP file containing all of the files you created for this assignment and submit it with the submission server. Chris Schmidt, last updated May 15, 2007 |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||