55.4k views
5 votes
A website requires that passwords only contain alphabetic characters or numbers. For each character in passwordStr that is not an alphabetic character or number, replace the character with 'y'.

Ex: If the input is 6$&QL, then the output is: Updated password: 6yyQL
#include
#include
using namespace std; int main() {
string passwordStr;
unsigned int i;
cin >> passwordStr;
(CODE HERE)
cout << "Updated password: " << passwordStr << endl; return 0;
}

1 Answer

1 vote

Final answer:

To replace characters in a password string that are not alphabetic characters or numbers with 'y': iterate through each character, check if it's alphabetic or a number, and replace if necessary.

Step-by-step explanation:

In order to replace characters in a password string that are not alphabetic characters or numbers with 'y', you can iterate through each character in the string and check if it is an alphabetic character or a number using the isalnum() function from the cctype library.

If the character is not an alphabetic character or a number, you can replace it with 'y'. Finally, you can output the updated password string.

User TruckerG
by
8.3k points