Assignment 5 - ldkvd/CS101L GitHub Wiki

Welcome to the CS101L Wiki!

Check Digit Program

The Linda Hall library wants to come up with a new library card numbering system for students. The card number’s first 5 characters are A-Z, which will normally be the first five characters of the student’s name. The next character at index 5 is a string value either 1, 2, or 3 which represents the different schools; SCE, School of Law, or College of Arts and Sciences. The character at index 6 is either 1, 2, 3, or 4. These are the grade levels; Freshman, Sophomore, Junior, and Senior. The next 2 characters are 0-9, and the last character at index 9 is the check digit to verify the previous values. The last character is also 0-9.

Answers: image 1 image 2 image 3 image 4

In this code, multiple functions are defined and called. Functions allow for the same piece of code to run multiple times. It reduces clutters, complexity, and duplication of codes. It breaks down a large program into smaller, easy-to-manage components. We can call one statement (the function), rather than writing the same code over and over for each time we want to check a library card.

The function character_value() will return an integer value for the character value. The function get_check_digit() will use a formula, to sum up, all the values of the indexes from 0 to 8 and take the module of the final value to return a check digit value. The function verify_check_digit() will run through if statements and for loops to check the validity of the library card. The function get_grade() will look at index 6 of the string and return the grade level. The function get_school() will look at index 5 of the string and return the student's school.

If the library card is valid, the program will print that the card is valid and the student's school and grade. If the library card is not valid, the program will print that the card is invalid and the error in which invalidity occurs.