APS105 Lab 3

Objective

The objective of this lab is to give you practice writing C programs that use functions and arrays.

Part 1: ISBN and Check Symbols

ISBN, the International Standard Book Number, is a special code that uniquely identifies books. There are ten-digit ISBN numbers (called ISBN-10 numbers), and 13-digit ISBN numbers (called ISBN-13 numbers) in use today. Here are two examples of ISBN-10 numbers:
0205080057
123456789X
and here is an ISBN-13 number:
9781904987833
(We are ignoring the dashes that are usually printed between groups of digits in the ISBN numbers.)

In both ISBN-10 and ISBN-13 numbers, the final (rightmost) symbol is called the check symbol. It is calculated based on the preceding digits, and acts as a check that the ISBN has not been mistyped.

For ISBN-10 numbers, we calculate the check symbol as follows. We begin by creating a weighted sum: take 10 times the first digit, add 9 times the second digit, add 8 times the third digit, and so on, until you add 2 times the ninth digit. Then, take the remainder of dividing this weighted sum by 11, and subtract this remainder from 11. If this final value is less than 10, it becomes the check symbol; if it is 10, the check symbol is the symbol X; if it is 11, the check symbol is 0.

For example, consider the first nine digits of the first ISBN given above:
020508005
The weighted sum is:
0*10+2*9+0*8+5*7+0*6+8*5+0*4+0*3+5*2
= 18+35+40+10
= 103
When we divide 103 by 11, the remainder is 4. Subtracting 4 from 11, we get 7. The check symbol (the last digit in the ISBN) is therefore 7. You should work out the second ISBN-10 example above to see why the check symbol is X.

For ISBN-13 numbers, we calculate the check symbol differently. First, we compute a sum: take 1 times the first digit, add 3 times the second digit, add 1 times the third digit, add 3 times the fourth digit, add 1 times the fifth digit, and so on, until you add 3 times the 12th digit. Then, take the remainder of dividing this sum by 10, and subtract this remainder from 10. If this final value is less than 10, it becomes the check symbol; otherwise, the check symbol is 0.

For example, consider the first twelve digits of the ISBN-13 number given above:
978190498783
The sum is:
9*1+7*3+8*1+1*3+9*1+0*3+4*1+9*3+8*1+7*3+8*1+3*3
= 9+21+8+3+9+4+27+8+21+8+9
= 127
When we divide 127 by 10, the remainder is 7. Subtracting 7 from 10, we get 3. The check symbol is therefore 3.

Download the files isbn.c and isbn.h. You will write the checkSymbol function in isbn.c. Do not modify isbn.h, and do not modify the parameters that checkSymbol takes or what checkSymbol returns.

As indicated in the comments, checkSymbol takes an array of integers representing an ISBN number, and a flag telling whether the array contains 9 or 12 elements. Based on the type of ISBN passed to the function, you will properly calculate and return the check symbol.

For this part, you are submitting only your checkSymbol function, no main function. However, you'll certainly want to test your function by calling it with various inputs. Download the file test_isbn.c, which includes a main function with some test cases. To test your checkSymbol function, compile your code with the following command:
gcc -o isbn isbn.c test_isbn.c
You should add further test cases to test_isbn.c; what I have included is enough just to get you started.

Part 2: First Row of Zeros

Download the files allzero.c and allzero.h. You will write the allZero function in allzero.c. Do not modify allzero.h, and do not modify the parameters that allZero takes or what allZero returns.

allZero takes two parameters: an integer n, and a two-dimensional array with n rows and n columns. As indicated in the comment, the function should print the index of the first row of all zeros in the array, and print nothing if there is no row of all zeros.

For this part, you are submitting only your allZero function, no main function. To get you started testing your function, download test_allzero.c. To test your allZero function, compile your code with the following command:
gcc -o allzero allzero.c test_allzero.c
Again, you are advised to test with further examples.

Submitting your Lab

When you have completed the lab, use the command submitaps105s 3 isbn.c allzero.c to submit your files. (By including only one filename, you can submit each file as you complete it.) Make sure you name your files exactly as stated (including lower/upper case letters). You may check the status of your submission using the command submitaps105s -l 3, where -l is a hyphen followed by the letter 'ell'.