



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A programming assignment that requires students to implement a bar code check sum algorithm in c++. The assignment covers array processing, functions, loops, and decisions. Students are asked to write functions to input a bar code, calculate the sum of odd-numbered digits, multiply even-numbered digits by 2 and add their digits, and compare the calculated check sum with the last digit of the bar code. The goal is to ensure the accuracy of bar code transmission.
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!
Name: Sec: 06/15/
This programming assignment continues to emphasize the use of arrays and functions, as well as practicing the use of loops and decisions to process information in arrays. The bar codes that you see on, for example, all of the groceries you buy and have scanned, are a technology that allow for the speedy and automatic labeling and transmission of product data. The bar codes used in most products include a check digit (the last digit in the bar code), which allows checking for transmission errors by the bar code reader. The basic idea (algorithm) used in a bar code reader is that the reader checks this last digit against a digit that is calculated from all of the real data/digits that the scanner has just read in. If the check digit matches the calculated check sum, there is a good chance that the bar code was scanned correctly, otherwise the bar code scanner will give some kind of an error (usually a beep) to indicate that the product didn't scan correctly. The use of check sums like this is a common practice for all types of electronic communication, including information sent over the internet. Check sums allow for a simple method to increase the reliability of transmission of data, and to detect when transmissions have been garbled. In this lab you will simulate some of the basics of a check sum algorithm for a bar code reader. We will give you the steps for the mathematical calculation of a check sum, and your job will be to implement these steps and simulate the scanning, check sum calculation and verification of a scanned bar code.
Review the basic array processing in C++, as well as practice writing functions, passing arrays to functions, and using the basic control structures to process arrays of data.
standard input by entering the individual digits of a bar code, separated by spaces. A terminal token, or special integer, will be used to indicate the end of the bar code. In this case we will use the value 999 t o indicate the end of the bar code. Therefore, a single bar code typed into your program might look like: 1 3 4 7 8 3 0 999 Notice there are spaces between each bar code digit, and the 999 sentinental is used to indicate the end of the input/transmission of the barcode. You will need to use a loop to read in the digits of the bar code, and store them in the array passed in to the inputBarCode function in successive indexes of the array. What will be the stopping condition of your loop? That is to say, how will you know when you need to stop reading digits from standard input and return from your function? Besides the digits that are read in, you will also need to return the number of digits that the bar code contains back to the caller. In the above example, the bar code contains 7 digits. You should pass back the size of the bar code, either as a result of calling the inputBarCode function, or using a reference parameter. Write a main() function where you call you inputBarCode function and test it before proceeding. You might find it useful to write another function, something like printBarCode, that takes and array of bar code digits and simply displays the digits in the array. In this way you can test calling you inputBarCode function and displaying the results to see if you input is working.
sum and should be compared directly with the passed in bar codes check digit. If the result is equal to 10, then 0 should be used as the check sum instead. The final result of correct or incorrect is determined by comparing the calculated check sum with the passed in check digit to see if they are equal or not. For example, still using our bar code of 1 3 4 7 8 3 0 The results from the previous steps were 13 and 17 respectively The check digit in the bar code is 0 (e.g. the last digit in the bar code). Adding 13 + 17 = 30 The remainder of dividing 30 / 10 is 0 (there is no remainder, it divides evenly by 10, do you remember how to find the remainder of a division between 2 numbers?) We subtract the remainder from 10 10 – 0 = 10 The result is 10 in this case, so we will use 0 as our check sum The check sum of 0 is equal to the check digit 0, so in this case the bar code transmission was correct, and we should return true as the result for our compareCheckSum function.
9 3 8 6 3 0 1 3 3 (WRONG check=4) 9 6 7 5 8 3 7 8 6 5 7 5 4 5 1 (CORRECT) 3 0 0 2 3 4 9 3 (CORRECT) 4 7 3 4 0 1 1 8 3 6 4 1 (WRONG check=4) 8 5 7 6 8 9 5 4 3 5 4 5 0 (WRONG check=2) 9 0 8 7 8 7 8 3 4 5 0 0 0 2 8 (CORRECT) 4 8 9 0 2 1 (CORRECT) 1 2 3 4 5 6 7 8 9 (WRONG check=6)
You have now completed Program 2. As with previous assignments, the final step you should perform when you complete an assignment is to upload your finished assignment to your eCollege account. Go ahead at this point and upload your Program2.cpp source file to eCollege. Once this is done you have successfully completed the programming assignment #2.