Note that the program must be written, compiled, and executed under Linux.
Create a directory called lab5 using the mkdir command and create your program files in this directory. Remember, in order to compile your program, you will need to use the g++ command.
In the public section, the class should define a constructor. It takes no parameters and simply sets all three of the private variables to 0.
The public section should also define the following methods:
A valid SSN is a 9-digit number (but remember it might contain dashes). For example, the following are valid SSNs: "555-66-5555", "555665555", "055441234". The following are not valid SSNs: "55-66-5555", "555ff6666", 0055-44-123a".
You can use the function isdigit to determine whether a single character is a digit or not. Its prototype is:
int isdigit( char c );
The function returns 0 if the character is not a digit and a
non-0 value if it is. Note that you must include the
ctype.h to use this function.
A string is being passed to the setSSN method, but you need to save
integer values. To convert a string value to an integer, you can use the
atoi function. The prototype for this function is:
int atoi( const char *ptr );
It takes a single string parameter and converts it to an equivalent integer.
For example, if the string "565" is passed, it returns the integer value 565.
Note that you must include stdlib.h to use this function.
Finally, write a main program, in the file main.cpp, that keeps a list
of 10 SSN's. Remember to include "ssn.h" at the top of this file too. You
will need to declare an array such as:
const int MAX_SSNS = 10;
SSN ssns[ MAX_SSNS ];
In a loop, the program should ask the user to enter in each SSN, read it in
as an array of characters, and call the setSSN method on the
appropriate ssns array element to set its value. If setSSN returns
false, a message should be printed saying an invalid SSN was entered and the
SSN should be re-entered.
After all 10 SSNs have been correctly entered, print the entire list, one to a line.
Finally, search the array for a SSN with a specified last 4 digits. Ask the user to enter a four-digit number (as an integer), then search the list and print all of the SSNs with the same last 4 digits. (For each array element, you can call the getLastFour method to get the value to compare against the value the user entered.)