CIS170C WEEK 5 LAB.docx

30 July, 2024 | 1 Min Read

Ā 

Week 5 Lab

#include < iostream > using namespace std;

const intSIZE = 80; const int MIN = 6; //function prototype int isValid(char pwd[]); intmain()

{ charpassword[SIZE]; while (true)

{

//put all of the conditions cout << “enter a password: “; cin.getline(password, SIZE);

if (isValid(password) == 1)

{ cout << “good password”; break;

}

else

{ cout << “password was invalid”;

}

}

system(“pause”) ;

}

int isValid(char pwd[])

{

//test each character and see if the boolean is set to true bool minLength =false; boolhasUpper = false; bool hasLower = false;bool hasDigit = false; intlength = strlen(pwd) ; if (length >= MIN)

{ minLength = true;

}

for (inti = 0; i < length; i++)

{

if (isupper(*pwd))//determines if the character is uppercase hasUpper = true;

//do the same for hasLower

//do the same for hasDigit

*pwd++; //increments your array to the next character

}

if (minLength == true && hasUpper == true&& hasLower == true&& hasDigit == true)return 1;

else

return 0; }

Related posts