Question

In: Computer Science

Write a C++ program that will use good object-oriented principles. You have been tasked to write...

Write a C++ program that will use good object-oriented principles.

You have been tasked to write an application that will allow a user to change their system password. The XYZ Corporation has the following rules for passwords:

  • each password should have a minimum of 8 characters
  • each password should have a minimum of 2 uppercase characters (A - Z)
  • each password should have a minimum of 2 lowercase characters (a - z)
  • each password should have a minimum of 2 digits (0 - 9)
  • each password should have a minimum of 2 special characters of which the following characters are allowed: !, @, $, %, and & (in any combination)

Once the user has created a new password that passes the above requirements, the user must then retype the password for the program to verify that the same password was entered by the user.

If the user creates a password that does not meet the minimum requirements, be sure to let the user know the entered password does not meet the minimum requirements and allow the user to retype the password.
If the user creates a password that does not match the second entry of the password (both entries much match), then be sure to let the user know the password update is unsuccessful.


If the password entered does not meet the minimum requirements, an error message should be displayed and allow the user to try again.

If the password entered contains the minimum requirements listed, then ask the user to retype the password for verification.
If the two entered passwords do not match, an error message should be displayed and the user should be allowed to retype the password.


An Example:

Update Your Password

Password Requirements:
- minimum of 8 characters
- minimum of 2 uppercase characters (A - Z)
- minimum of 2 lowercase characters (a - z)
- minimum of 2 digits (0 - 9)
- minimum of 2 special characters: !, @, $, %, &, _

Enter a new password: Pa$$word123

Error: password does not meet minimum requirements, try again:

Enter a new password: Pa$$Word123

Password meets minimum requirements.

Reenter the new password: Pa$$Word223

Error: update unsuccessful. Entries do not match, try again:

Reenter the new password: Pa$$Word123

Password Update successful.


Remember to change your password every 90 days.




The program should have as a minimum:

a class named Password

private member variables:

  • string to hold the initial password entry
  • string to hold the second password entry
  • int variables (4 minimum) to hold the count of:
    • number of uppercase characters entered
    • number of lowercase characters entered
    • number of digits entered
    • number of valid special characters entered

private member functions (all called from the driver() method):

  • void setPassword1() - prompts and reads in the initial password entry from the user
  • void validateRequirements() - validates the initial password entered meets the minimum requirements established
  • void setPassword2() - prompts the user to reenter the password and reads in the value entered ONLY when the initial password is valid
  • void validateMatch() - validates that both password entries match exactly
  • void display() - displays the result


public member functions:

  • class constructor - initialize variables
  • void driver() - called from main() and is the order of execution


!!!NOTE: any program submission that does not use a class and object and/or does not use appropriate methods will result in a grade submission of 0.
Use of global variables will also result in a grade submission of 0.

Solutions

Expert Solution

#include <iostream>// needed for cin and cout
#include <string.h>

using namespace std;

class password {
private:
    char passwrd[20],repass[20];
    int min_upper,min_lower,min_digit,min_special;
    int valid,valid2;
    void setPassword1();
    void validateRequirements();
    void setPassword2();
    void validateMatch();
    void display();
public: 
    void driver();
    password();
    };
    
void password::driver()
{
    setPassword1();
    validateRequirements();
    setPassword2();
    validateMatch();
    display();
    
}

password::password()
{
    valid=0;
    valid2=0;
    min_upper=min_lower=min_digit=min_special=0;
    
}
    
void password::setPassword1()
{
    cout<<"Update Your Password"<<endl;
    cout<<"Password Requirements:"<<endl;
    cout<<"- minimum of 8 characters"<<endl;
    cout<<"- minimum of 2 uppercase characters (A - Z)"<<endl;
    cout<<"- minimum of 2 lowercase characters (a - z)"<<endl;
    cout<<"- minimum of 2 digits (0 - 9)"<<endl;
    cout<<"- minimum of 2 special characters: !, @, $, %, &, _"<<endl;
    cout<<"Enter a new password:";
    cin>>passwrd;

}

void password::validateRequirements()
{
 int invalid=0;
 while(1)
    {
    
    int l=strlen(passwrd);
    //cout<<endl<<"lenght"<<l<<passwrd<<endl;
    for(int i=0;i<l;i++)
    {
        char c=passwrd[i];
        if(c>='a' && c<='z')    //count lowercase characters (a - z)
            min_lower++;
        else if(c>='A' && c<='Z') //count uppercase characters (A - Z)
            min_upper++;
        else if(c>='0' && c<='9')  //count digits
            min_digit++;
        else if(c=='!' || c=='@'||c=='$'||c=='%'||c=='&'||c=='_') //count special chars
           min_special++;
        else
            {
                invalid++; //counts invalid special characers +,=,(,)etc
                cout<<"invalid special character"; 
            } 
    
                
    }
    //if all requirement true, set valid=1
    if(l>=8 && min_special>=2&&min_digit>=2&&min_upper>=2&&min_lower>=2&&invalid==0)
     valid=1;
     else
     valid=0;
     
     //cout<<valid<<"????";
    if(valid==0)
     {
        cout<<"Error: password does not meet minimum requirements, try again:";
        cin>>passwrd;
        min_upper=min_lower=min_digit=min_special=0;
        
        
     }
    else
     {
    // cout<<"length"<<min_lower<<min_upper<<min_digit<<min_special<<endl;
    //  cout<<"ok"<<endl;
       break;
     }
    }
    
     
}

void password::setPassword2()
{
   if(valid)     //if first password valid, reenter the Password
    {
     cout<<"Password meets minimum requirements."<<endl;
     cout<<"Reenter the new password:";
     cin>>repass;
    }
}


void password::validateMatch()
{
   while(1)
   {
       if(strcmp(passwrd,repass)!=0)  //if both password are different,unsuccess
       {
          cout<<" Error: update unsuccessful. Entries do not match, try again:"<<endl;
          cout<<"Reenter the new password:";
          cin>>repass;
          valid2=0;
       }
       else
          {
              valid2=1;
              break;
          }
   }
}

void password::display()
{
  if(valid2==1 && valid==1)   //if both passwords match, success
  {
      cout<<"Password Update successful."<<endl;
      cout<<"Remember to change your password every 90 days.";

  }
}

int main()
{
    password pw;
    pw.driver();
    return 0;
}
 

Related Solutions

This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
Intro C++ Programming Chapter 6 Functions You have been tasked to write a new program for...
Intro C++ Programming Chapter 6 Functions You have been tasked to write a new program for the Research Center's shipping department. The shipping charges for the center are as follows: Weight of Package (in kilograms)                Rate per mile Shipped 2 kg or less                                                      $0.05 Over 2 kg but no more than 6 kg    $0.09 Over 6 kg but not more than 10 kg    $0.12 Over 10 kg    $0.20 Write a function in a program that asks for...
Problem Write a movie management system using object-oriented design principles. The program will read from the...
Problem Write a movie management system using object-oriented design principles. The program will read from the supplied data file into a single array list. The data file (movies.txt) contains information about the movies. Each movie record has the following attributes: - Duration (in minutes) - Title - Year of release Each record in the movies.txt file is formatted as follows: - Duration,Title,Year - e.g.: 91,Gravity,2013 Specifically, you have to create an interactive menu driven application that gives the user the...
design a program that solves matrices by the method of gauss-seidel use the object-oriented language c...
design a program that solves matrices by the method of gauss-seidel use the object-oriented language c ++
In this program, you are modifying given code so that the class is object-oriented. 2. Write...
In this program, you are modifying given code so that the class is object-oriented. 2. Write a Java class called CityDistancesOO in a class file called CityDistancesOO.java.    3. Your class will still make use of two text files. a. The first text file contains the names of cities with the first line of the file specifying how many city names are contained within the file.    b. The second text file contains the distances between the cities in the...
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a...
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a Student, and then finally GPA. Have items neatly line up in columns. I need help creating a derived class called student that finds GPA (between 0.0 and 4.0) and credits completed (between 0 and 199).
Practice object-oriented principles by making two Peanut Butter and Jelly Sandwiches. The program must create two...
Practice object-oriented principles by making two Peanut Butter and Jelly Sandwiches. The program must create two sandwiches based on user input. The sandwich information for both must then print out their details and determine if the two sandwiches are equal. Requirements:   Write a class called Bread with the following Instance Variables Name: The name brand of the bread. o   Calories: The number of calories per slice assumed to be between 50 and 250 inclusively. Type: The kind of bread. This can...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
PLEASE DO IN C++ Create an object-oriented program that initially allows the user to save customer...
PLEASE DO IN C++ Create an object-oriented program that initially allows the user to save customer information in the list and to search for a customer by specifying the customer’s ID. Sample Run Customer Information Management System --------------------------------------------------------------- CUSTOMER DATA ENTRY: Full Name (First, Last): Jenny Ha Company: Convergent Laser Technologies Street: 1000 International Ave City: Oakland State: CA Zip Code: 94506 ID: 100 Continue Your Data Entry? (y/n): y Full Name (First, Last): Bill Martinez Company: Cisco Systems Street:...
As the head of the local Criminal Justice Dept. You have been tasked to write changes...
As the head of the local Criminal Justice Dept. You have been tasked to write changes to departmental policy because of a recurring problem involving students failing to appear in class or appearing late in class. The dean has complained to you because he thinks attending class is a low priority for you students. Using cause and effect determine the possible causes for the late and missed classes. List the possible causes under the headings below Machines 1 2 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT