Question

Here is the skeleton of the password checking program. We have the character counting function (you...

Here is the skeleton of the password checking program. We have the character counting function (you will need to finish it), and a function to check if the password is good.

Change the password algorithm so that (three of the four) two uppercase, two lowercase, two digits, or one other is present. Also change the required length of the password to 10.

Bonus points for making the program loop until a good password is entered. You will need to read the new password inside the loop if the originally entered password is not good.

// string-character-count
#include <iostream>
#include <string>
using namespace std;
void characterCount(string text, int &upper, int &lower, int &number, int &other) {
   int count[256] = {};
   upper = lower = number = other = 0;
  
   for(int i=0;i<text.length();i++)
       count[text[i]] += 1;
  
   for (int c=48;c<58;c++)   // number digits
       number += count[c];
  
   // calculate upper count, lower count, and other count
  
   /*
   // this displays the count for each character
   for(int i=0;i<256;i++) {
       if (count[i] > 0)
           cout << i << "\t" << (char) i << "\t" << count[i] << endl;
   }
   */
}
bool isGoodPassword(string password) {
   int upper, lower, digit, other;
   int criteriaMet = 0;

   characterCount(password, upper, lower, digit, other);
   if (password.length() >= 8) {
       if (upper > 0) criteriaMet++;
       if (lower > 0) criteriaMet++;
       if (digit > 0) criteriaMet++;
       if (other > 0) criteriaMet++;
       if (criteriaMet >= 3)
           return true;
       else
           return false;
   } else
       return false;
}

int main() {
   string text;
   int upper, lower, number, other;
  
   cout << "Enter text:";
   getline(cin, text);
   characterCount(text, upper, lower, number, other);
   cout << "Upper:\t" << upper << "\tLower:\t" << lower
       << "\tNumber:\t" << number << "\tOther:\t" << other << endl;
   if (isGoodPassword(text)) {
       cout << "That is a good password!" << endl;
   } else {
       cout << "Not a good password, try again." << endl;
   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <string>
using namespace std;
void characterCount(string text, int &upper, int &lower, int &number, int &other) {
int count[256] = {};
upper = lower = number = other = 0;
  
for(int i=0;i<text.length();i++){
if(text[i]>='A' && text[i]<='Z')
upper++;
else if(text[i]>='a' && text[i]<='z')
lower++;
else if(text[i]>='0' && text[i]<='9')
number++;
else
other++;
}
}
bool isGoodPassword(string password) {
int upper, lower, digit, other;
int criteriaMet = 0;

characterCount(password, upper, lower, digit, other);
if (password.length() >= 10) {
if (upper >=2) criteriaMet++;
if (lower >=2) criteriaMet++;
if (digit >=2 || other>=1) criteriaMet++;
if (criteriaMet >= 3)
return true;
else
return false;
} else
return false;
}

int main() {
string text;
int upper, lower, number, other;
while(true){
cout << "Enter text:";
getline(cin, text);
characterCount(text, upper, lower, number, other);
cout << "Upper:\t" << upper << "\tLower:\t" << lower
<< "\tNumber:\t" << number << "\tOther:\t" << other << endl;
if (isGoodPassword(text)) {
cout << "That is a good password!" << endl;
break;
} else {
cout << "Not a good password, try again." << endl;
}
}
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Here is the skeleton of the password checking program. We have the character counting function (you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all th...

    My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...

  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

  • 3.14.1: String with digit. Set hasDigit to true if the 3-character passCode contains a digit. HELP...

    3.14.1: String with digit. Set hasDigit to true if the 3-character passCode contains a digit. HELP ME FIX THIS #include <iostream> #include <string> #include <cctype> using namespace std; int main() { bool hasDigit; string passCode; hasDigit = false; cin >> passCode; for(int i=0;i<passCode.length();i++) { if(isdigit(passCode[i])) { hasDigit=true; break; } } if (hasDigit) { cout << "Has a digit." << endl; } else { cout << "Has no digit." << endl; } return 0; }

  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

  • Can you fix this program and run an output for me. I'm using C++ #include using...

    Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) {    int uniqueDigitCount = 0;    int storeDigit = 0;    int digit = 0;    while (input > 0) {        digit = 1 << (input % 10);        if (!(storeDigit & digit)) {            storeDigit |= digit;       ...

  • Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2...

    Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2 - Stack around the variable 'string4b' was corrupted. I need some help because if the arrays for string4a and string4b have different sizes. Also if I put different sizes in string3a and string4b it will say that those arrays for 3a and 3b are corrupted. But for the assigment I need to put arrays of different sizes so that they can do their work...

  • Need help with a C++ program. I have been getting the error "this function or variable...

    Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) {    // average function , declaring variable    int i;    char str[40];    float avg = 0;    // iterating in...

  • Create a program via Java that has atleast 8 characters long, one upper case, and one...

    Create a program via Java that has atleast 8 characters long, one upper case, and one lower case, and one digit. here is my code:     public static void main(String[] args)     {         //variables defined         String passwords;         char password =0;                 //settings up password condition to false         boolean passwordcondition= false;         boolean size=false;         boolean digit=false;         boolean upper=false;         boolean lower=false;         //inputting a scanner into the system         Scanner keyboard = new Scanner(System.in);...

  • c++ Implement the following function: 1) Name: ProcessLine a. Parameters: Int 10 character array line, charc...

    c++ Implement the following function: 1) Name: ProcessLine a. Parameters: Int 10 character array line, charc b. Job: The function will modify line such that every occurrence of c is replaced by a "*". It will also return the count of c in line. The main() function is provided. You only need to implement the function Processline. #include <iostream> #include <string> using namespace std; int main() char line 200), c; int Count; { cout<<"Enter some text: "; cin.get(line, 200); cout<<"Enter...

  • Why the result is 0. The correct result should be 2 but it is 0. Why?...

    Why the result is 0. The correct result should be 2 but it is 0. Why? File Edit using std:istring int numVowels(string str) Exited with status int str len str. length); int i int count for (i=0; î <str-len; i++) /s Convert the character to 1 /s If the character is atready in Lower case, tolower) will return temp tolower(strli]): />If the character is any of these five letters ,a", 'e', 'i', 'o', 'u count++ /- Return the count value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT