Home / Expert Answers / Computer Science / a-3-character-string-userpassword-is-read-from-input-check-if-the-first-and-second-characters-in-pa966

(Solved): A 3-character string, userPassword, is read from input. Check if the first and second characters in ...



A 3-character string, userPassword, is read from input. Check if the first and second characters in userPassword are alphabetic characters. Replace the alphabetic characters (if any) with '%'. If neither character is alphabetic, userPassword is not changed.

Ex: If the input is mbx, then the output is:

%%x

Ex: If the input is y08, then the output is:
%08

A 3-character string, userPassword, is read from input. Check if the first and second characters in userPassword are alphabet

A 3-character string, userPassword, is read from input. Check if the first and second characters in userPassword are alphabetic characters. Replace the alphabetic characters (if any) with '\%'. If neither character is alphabetic, userPassword is not changed. Ex: If the input is mbx, then the output is: \[ \circ \% \mathrm{x} \] Ex: If the input is \( y 08 \), then the output is: \[ \text { \%08 } \] - us lily mulliespuce siu, 6 int main() \{ 7 string userPassword; 9 getline(cin, userPassword); 11 I/isalpha is a part of cctype header file 12 //checks if the parameter passed to it is alphabetic or not, returns 1 if yes 0 if not 13 if (isalpha(userPassword[0]) \&\& isalpha(userPassword[2])) \{ 14 I/we check if character at 0th index and 2nd index are alphabetic 15 II if both are alphabetic we replace them with '. ' as specified in the question userPassword[0] = '\%'; userPassword[1] = '\%'; \} cout \( \ll \) userPassword \( << \) endl


We have an Answer from Expert

View Expert Answer

Expert Answer


C++ code: // for input output #include // for string object #include // for isalpha function define in it #include using namesp
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe