ESc 014

Lab 6 -- CheckSums
Thursday, May 16, 2002

Objectives

Introduction

A local bank has instituted a new credit system and would like to have account numbers that are self-checking in order to have some protection against fraud and clerical errors. They have devised the following system: the account numbers will be nine digits long where the last digit can be calculated by finding the sum of the first eight digits and taking the rightmost digit of the sum. For example, if the account number was 333333334, the sum of the first eight digits is 24. 4 is the rightmost digit of 24 which equals the ninth digit of the account number. Therefore, the account is valid. The ninth digit of the account is called a checksum.

Your Mission

Your job is to complete a program that can be used to check the validity of account numbers.

First, you should download the starter code and input file from blackduck. In the "esc014pub" directory is a directory named "lab 6". Transfer this directory to the DesktopAnnex folder on your desktop. Go back to lab 1 if you need a refresher on the instructions.

Inside the "lab 6" folder is an input file of account numbers named "accounts.txt". Each account number is on a separate line. The last line is a semicolon that you can use as a sentinel to determine when the input file ends. There is also starter code named "yourNameHere.cpp". Change the filename to your own name (keep the .cpp extension). You should NOT alter this code.

Besides the main function, two auxiliary functions have already been written for you. The first, called validChecksum, returns true if the given checksum character is equal to the last digit of the given sum. It returns false otherwise. In the example above, giving validChecksum the checksum character '4' and the sum of 24 as parameters would return true.

The other function given to you is digitToNumber. It converts the given char to its equivalent representation as an int. It's the same function given to you on p. 357 of your text.

The Details

The function you will write is named processData. It takes no parameters. This function will read in the account numbers character-by-character using the get command. As it reads in the characters, it will compute the sum of the first 8 digits, read in the checksum (ninth) digit, and then call validChecksum to determine if the account number is valid or not. It should then inform the user if the account number is valid or not. Your output will look something like this:
333333334 is a valid account number.
111111110 is an invalid account number.
... etc.
Make sure to process the input yourself by hand to check the validity of your test results.

How to turn in this lab

Remember, you will be graded on the correctness of your implementation, neatness, presentation, style of your program code, thoroughness of your testing, and good use of the C++ language. It's important to comment your code where appropriate and to do little things like space things properly, use readable indentation, and also to make sure the overall design and logic of the program are coherent.

Turn in a hard copy of your source code along with your test results appended at the bottom as a comment. Then turn in the source code electronically on BlackBoard.


Return to Lab Index