Project Six Strings and Vectors Write a C++ program that allows the user to input these string values: 1- User’s first name into firstName. 2- User’s last name into lastName. 3- User’s password into password The program places the first letter of the first name plus the first 5 characters of the last name into the string userName. You can assume the last name is at least 5 characters. The program then concatenates userName and password into a string variable login. login takes the form userName, password (note the comma and space) For example pmadis, abc123 The combined strings will then be stored in a string vector. Before combining the strings, write a function named checkPassword to request the password and validate the entry. The function should verify the following: o Length of the string is at least 5 characters. Error message =: Password is not 5 characters. o Cannot contain a space. Error message =: Password cannot contain a space. Place the error messages in a string array, and display the messages before requesting the password in checkPassword. Display the appropriate error message when you find an error. Repeat the loop until the user enters a valid password. The function should return the string to main after the entry is correct. Repeat the process of entering user names and passwords until the user enters 0 for firstName. Output the list to the screen by displaying the vector items (the logins) one per line after building the vector. Set up the string password = “abc123”; and test the vector code first. After the vector code in main works: o Change string password = “abc123”; to string password; o Add the checkPassword function. o The call should look like this: password = checkPassword(); o The checkPassword function returns the password after it is validated. The getline for password should be in checkPassword. o Use getline to input the user name and password. Here is the syntax: getline(cin, s); s is declared as a string. |
|
|
15: string checkPassword();
outside of main.) -opinion17: firstName = "1";
not necessary30: lastName = lastName.substr(0,5);
34: userName = firstName[0] + lastName;
Why write firstName[0] and not just firstName?88: while (errorFlag = false);
|
|
17: firstName = "1"; |
30: lastName = lastName.substr(0,5); |
34: userName = firstName[0] + lastName; |
88: while (errorFlag = false); |
90: string returnedPass[] = { userPassword }; 91: 92: return(returnedPass[0]); |
30 & 34: The prompt says that the username should be the first character of firstName and the first five characters of lastName. In 30 I intended to redefine lastName as the first five characters of what came in from getline(cin, lastName). In 34, I pulled the character in position 0 to get the first character. For both, is a different (better) way to have coded it? |
The reason I did this was because I read that you couldn't return a string out of a function directly. |