Description
The purpose of this challenge is to create and use basic classes. This challenge creates a password-strength verification system.
Requirements
- Create the class below
class KeywordReqs { private: string keyword; int min_len; int min_uppers, min_lowers; int min_digits; };
- Add the following private functions:
- int count_uppers() – returns the number of upper case characters in keyword.
- int count_lowers() – returns the number of lower case characters in keyword.
- int count_digits() – returns the number of digit characters in keyword.
- Add an overloaded constructor to set keyword from a parameter value
- Add the following public functions:
- void set_reqs( /* a list of parameters */ ) – this function is used to set the private variables min_len, min_uppers, min_lowers, min_digits
- bool is_valid() – returns true or false – the function verifies that keyword satisfies the minimum requirements of upper case, lower case, length and digits.
- bool is_valid(string test) – this is an overloaded function similar to (2) above. This version validates test (not the private keyword property) against the minimum requirements. Depending on how you write this function, you could edit the signatures of the private count_xyz() functions above to make things easier – can you figure it out?
- Use string types. No need to use char-array types. Remember that string types allow access to individual characters using array indexing. Also the .length() function can be applied to string types to determine its length.
- Copy the starting code below. You can add more driver code if you like:
void show(bool value) { cout << (value ? "Valid" : "Not Valid") << endl; } int main() { // initialize a KeywordReqs instance KeywordReqs password("abc123"); password.set_reqs(6, 3, 3, 3); // len, lowers, uppers, digits show(password.is_valid()); // shows Not Valid show(password.is_valid("COVID2019virus)); // shows Valid show(password.is_valid("StrangerThings")); // shows Not Valid show(password.is_valid("six7")); // shows Not Valid // add more code to fully test various combinations return 0; }
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-CHAL00079
Print Requirements