Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Strings and Vectors This program will be creating a vector with logins made up o

ID: 3571939 • Letter: S

Question

Strings and Vectors

This program will be creating a vector with logins made up of user names and passwords.

Part I – Creating a vector composed of user names.

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.

The program places the first letter of the first name plus the first 5 characters of the last name into the string login. You can assume the last name is at least 5 characters. The combined strings (login) will then be stored in a string vector. Repeat the process of entering user names 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.

Part II – now add a password to the login after checking the password for errors.

Before adding the password to the login string, write a class named Validate (Validate.h) to validate the entry. The class should have the following functions:

displayMsg Displays the messages in the message array so the user knows the rules for creating the password.

checkLength Length of the string is at least 6 characters.

Error message =: Password must be 6 characters.

Returns true if the length is incorrect and false if the length is correct.

checkSpaces Cannot contain a space.

Error message =: Password cannot contain a space. Returns true if there are spaces and false if there are no spaces.

checkUpper One character must be an upper case letter.

Error message =: One letter must be upper case. Returns true if there are no upper case letters and false if there is an upper case letter.

The Validate class should contain: Constructor that receives a string

These functions:

displayMsg

checkLength

checkSpaces

checkUpper

These variables/constants:

String entry;

cons int LEN = 6; //use this constant in checkLength.

String array containing error messages. Use this array to display any messages

required in the functions.

Here is the pseudocode for using the Validate class: In the while loop in main, add a do loop that calls the displayMsg function in the do loop before the request for a password. Use a default constructor to instantiate the object for displaMsg. Requests a password. instantiates an object using the constructor in Validate call the functions to validate the password. repeat the loop if true is returned from any of the 3 called functions Display any and all error messages.

After the password is validated, add a do loop to request the password a second time. This loop should verify that the first password entered is the same as the second entry. If not, display an error message using the message array and request the password again. When checking to ensure the second password is the same as the first, display an error message such as " Passwords are not identical." but it does need to be in the message array in the Validate class.

SAMPLE OUTPUT

LOGIN LIST

ENTER FIRST NAME OR 0 TO STOP : JOHN

ENTER LASTNAME : JOHNSON

PASSWORD RULES

PASSWORD MUST BE 6 CHARACTERS

PASSWORD CANNOT CONTAIN SPACES

ONE LETTER MUST BE UPPER CASE

ENTER PASSWORD : 123

PASSWORD MUST BE 6 CHARACTERS

ONE LETTER MUST BE UPPER CASE

PASSWORD RULES

PASSWORD MUST BE 6 CHARACTERS

PASSWORD CANNOT CONTAIN SPACES

ONE LETTER MUST BE UPPER CASE

ENTER PASSWORD:

After the two passwords match, add the password string to the login before storing it in the vector. login takes the form username, password

For example: pmadis, Abc123 Note the addition of the comma and space between the username and password.

Purpose is to Develop C++ program with the following features:

Strings – Use the string class.

Vectors

Character functions

*Be sure to add #include <string>

Add the code for Part I and then Part II.

Use getline to input the user name and password. Here is the syntax:

          getline(cin, s);

         s is declared as a string.

Explanation / Answer

#include<iostream.h>

#include<vector.h>

#include<conio.h>

#include<string.h>

using namespace std;

int main()

{

string Fname, Lname, password, Uname, login;

vector<string>list;

string Check_Password();

cout<<" Please enter the First name or 0 to exit ";

getline(cin,Fname);

while(Fname!="0")

{

cout<<" Enter Last name:";

getline(cin,Lname);

Lname=Lname.substr(0,5);

password= checkpassword();

Uname=Fname+Lname;

login=username+","+password;

list.push_back(login);

cout<<" Enter the First name or 0 to exit";

getline(cin,Fname);

}

cout<<" Login list:";

for(int n=0;n<list.size();++n)

{

cout<<list.at(n);

system("pause");

return 0;

}

string checkpassword()

{

bool errorflag= false;

string userpassword;

cout<<" Enter the password:";

getline(cin,userpassword);

do

{

int n= userpassword.length();

if(n<5)

{

cout<<"Password must be 6 characters";

errorflag=true;

cout<<" Enter the user password:";

getline(cin,userpassword);

}

size_t found= userpassword.find(' ');

if(found!=string::npos)

{

cout<<' Password cannot contain spaces:";

errorflag=true;

cout<<" Enter the user password:";

getline(cin,userpassword);

}

}

while(errorflag=false);

string returnedpass[]={userpassword};

return (returnedpass[0]);

}