Don's Lock and Safe Company needs a program to help him assist his customers in creating 4-number safe combinations. Don has a pencil-and-paper system and hed like to automate the process.
Don's system is simple. He uses a classic telephone keypad to translate characters into a single digit. Here is an image of a keypad.
Figure: see image.
Don't asks his customers to give him an 8-character phrase containing no spaces, numbers, or special characters. The corresponding numbers on the phone become the digits of the generated combination.
For example, if I gave him the string "Johnston", it would translate into this safe combination:
J -> 5 o -> 6 | h -> 4 n -> 6 | s -> 7 t -> 8 | o -> 6 n -> 6 |
56 | 46 | 78 | 66 |
The safe combination for the "Johnston" code is 56-46-78-66.
There are certain restrictions on the lock combinations, due to the mechanics, lock design and dialing tolerances. Since the Underwriter's Laboratory specify locks have a 1.25+ digit tolerance we are going to require that the combinations not have values within 4 digits of one another. That means, if a combination has two numbers within (and including) 4 numbers apart, it will be considered invalid.
For example, the combination 55-59-24-88 is invalid because 55 and 59 are within 4 digits. The combination 55-24-88-59 is also invalid.
Additionally, combinations cannot have the same number twice. The combination 58-25-94-25 is invalid because 25 appears twice in this combination.
In your implementation, you must have functions that match the following table:
Required Function Prototype (Declaration) | Specification |
string askForPhrase(); | Asks the user to enter an 8 character phrase with no digits, spaces, or special chars. NOTE: no error checking is done in this function. |
bool validatePhrase(string input, string* desc); | Passed the user's input and performs error checking on input. Returns a boolean value (true/false) that is true if the input is valid, or false if it is not valid. The desc variable describes the problem with the phrase. The string pointed to by desc should be assigned to a string that tells the user what went wrong, such as "contains a space", "contains a digit", etc. If the string is valid, the desc should be assigned to a string that indicates the input is valid, such as "valid". |
void createCombo( string input, struct ComboNumbers& rCombo); | Passed a valid input string and returns the four numbers that represent the combination. The implementation should call twoCharsToInt. |
bool validateCombo(struct ComboNumbers combo, string *desc); | Validates the combination. Returns a true/false value indicating whether the combination is valid or not. The desc argument describes the problem with the combo, and the string it points to should be assigned before exiting the function. Example values include "duplicate numbers", or "numbers too close together". |
bool WriteCombo(struct ComboNumbers combo, string filename); | Open, check, and, if successful, write a file with the validated combination. |
NOTE: For full credit, your code must include the functions described.
Your information to the user should be neatly formatted in complete, brief sentences.
In your Functions.h, declare a struct with the four combo numbers. Name the struct ComboNumbers.
Your main method should:
Except for your header() and askForPhrase () function ALL output is displayed to the user from main. No other functions write any information to the screen!