Description

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:

  • Show your header (write a separate function if you wish).
  • Create a struct ComboNumbers instance (a variable of type struct ComboNumbers). Name it combos.
  • Begin a do while loop.
  • The user should be asked for their phrase.
  • If the phrase is invalid, ask if they would like to enter another phrase or quit. If they choose to enter another phrase, go back to the beginning of the do-while loop. If they choose to quit, drop out of the do-while loop and print a goodbye statement.
  • Create the combination based on the phrase
  • Report the resultant combination and whether it is valid and usable as a safe combination.
  • If the combination is invalid, ask if they would like to enter another phrase or quit. If they choose to enter another phrase, go back to the beginning of the do-while loop. If they choose to quit, drop out of the do-while loop and print a goodbye statement.
  • Call WriteCombo, so that the user has a written record of their combination.
  • Check the bool return from the WriteCombo function and report the success/failure of the file writing.
  • When the user is finished, the code logic should drop out of the do-while loop and print a goodbye statement.

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!

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.