View the step-by-step solution to:

ok i wrote this program can you look over it and see if its correct

ok i wrote this program can you look over it and see if its correct

/Author: Mervyn Sealey //Source File: Password.cpp //Description: Password Program //IDE used: Visual Studio C++2015 #include <iostream> #include <vector> #include <string> using namespace std; string checkPassword(){ vector<string> errorMessages; errorMessages.push_back("Password is not 5 characters"); errorMessages.push_back("Password cannot contain a space"); errorMessages.push_back("One letter must be upper case"); string password; int errorMessageIndex=0; bool errorFlag=false; do{ if(errorFlag==true){ cout<<errorMessages[errorMessageIndex]<<endl; } cout<<"Enter password : "; getline(cin, password); /* Checking if size of password is less than 5*/ if(password.size()<5){ errorFlag=true; errorMessageIndex=0; continue; } /* Checking if space is present*/ int isSpace=false; for(int i=0;i<password.size();i++){ if(password[i]==' '){ isSpace=true; break; } } if(isSpace==true){ errorFlag=true; errorMessageIndex=1; continue; } /* Checking if capital letter is present or not*/ int countAlphabets=0; for(int i=0;i<password.size();i++){ if(!(password[i]>='A' && password[i]<='Z')){ countAlphabets++; } } if(countAlphabets==password.size()){ errorFlag=true; errorMessageIndex=2; continue; } /* all conditions checked*/ errorFlag=false; }while(errorFlag == true); return password;
Background image of page 1
} int main( ) { string firstName; string lastName; string userName; string login; string password; vector<string> v; cout << "Enter a list of user names and passwords.\n" << "Place a zero as first name at the end.\n"; while (1) { cout<<"Enter first name : "; getline(cin,firstName); if(firstName=="0"){ break; } cout<<"Enter last name : "; getline(cin,lastName); userName = firstName[0] + lastName.substr(0,5); password=checkPassword(); login=userName+", "+password; v.push_back(login); } cout << "You entered:\n"; for (unsigned int i = 0; i < v.size( ); i++) cout << v[i] << endl; return 0; }
Background image of page 2
Page 1 of 3 Project Seven Strings and Vectors This program will be creating a vector with logins made up of user names and passwords. I suggest writing this project in two parts to eliminate the frustration of trying to code/test too much code at one time. 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 userName . You can assume the last name is at least 5 characters. The program then concatenates userName with a comma and space into a string variable login. login takes the form userName, (note the comma and space). *The comma and the space will make more sense when you add the code in Part II. For example pmadis, The combined strings will then be stored in a string vector. See Display 8.4 for sample code concatenating strings, and Display 8.7 for a list of string functions. 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. See lines 18-20 in 08.09.cpp.
Background image of page 1
Page 2 of 3 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 functions to verify the following: o checkLength Length of the string is at least 5 characters. Error message =: Password is not 5 characters. Returns true if the length is incorrect and false if the length is correct. o 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. o 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: checkLength checkSpaces checkUpper These private variables/constants: String password; Static cons int LEN = 5; //use this constant in checkLength.
Background image of page 2
Show entire document
Sign up to view the entire interaction

Top Answer

Please find attached the required answer. I have corrected and... View the full answer

Password.cpp

// Author: Mervyn Sealey
//Source File: Password.cpp
//Description: Password Program
//IDE used: Visual Studio C++2015
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online