Credit Card Number Validator
Name: Paul Picazo
Course: SE 320 (Chadwick)
Table of Contents
Requirements
- Input
- string to verify if it is a valid credit card number
- Output
- the credit card number string inputed and the result of
whether or not it is valid
- Constraints
- must be able to validate any 16 digit credit card number
using the luhn method
- program format per CS225 style requirements 1-6
- User interface
- Extra credit
Design
- Input:
- string to verify if it is a valid credit card number
- Output:
- the credit card number string inputed and the result of whether
or not it is valid
- Components:
- User interface (in main because it was quick and professor
didn't require seperate UI function for this assignment)
- Credit Card Number Validator fucntion
- Support functions
- Departures from requirements:
Test scenarios
- input empty;
creditcard should be reported as invalid
- input is of improper length;
creditcard should be reported as invalid
- input digits are of non integer type;
creditcard should be reported as invalid
- input contains whitespace;
creditcard should be validated without those spaces
- input is valid creditcard number;
output should show the creditcard number and then show if it was valid
or not
- input is all zeros;
this is a valid according to the luhn method, so it should work as
other valid creditcards
Implementation
- Implementation Design
- main()
- get user input
- send user input to checkCC()
- if user input equals true
- print input
- print that it is a valid creditcard
- else
- print input
- print that it is not a valid creditcard
- checkCC()
- call removeSpaces() to remove spaces from input
- check to see if input is 16 characters in length
- if not 16 characters in length set retVal to false
- check to see if input contains only numeric digits
- if not set retVal to false
- starting with the 2nd to last digit in the input
- times digit by 2
- convert result to string with itos()
- and insert it in the current place (shifting anything to
the right as needed) in the input
- move over two digits tp the left and repeat until we can't
move anymore digits to the left
- itterate through each digit of the result
- call atoi() to convert it to an integer
- add it in to the sum (starts at zero)
- divide sum by 10
- if remainder is zero, then set retVal to true
- removeSpaces()
- return a string with any spaces removed
- itos()
- return a string representation of an integer
- Implementation test scenarios
- main()
- ensure that proper result from checkCC is printed to
screen
- checkCC()
- ensure that the values of the parameters are the same as
their corresponding variables in GravityUI()
- removeSpaces()
- ensure that all spaces have been removed and only spaces
have been removed
- itos()
- esure that the function works like itoa(), at least enough
to work in this program like itoa() did, but returning a string instead
of a char*
- Code:
Successes and failures
- Everything worked when compiled on Visual Studio 2005 C++
Express, but apparently itoa() is not standard so the version of g++ on
linux I tried failed. So a simple function was created in order
eliminate uses of itoa() in the code.
- Code will print non visible characters if inputed (in linux),
this should be fixed.