jeudi 23 juin 2022

Can't seem to make the functions work on my code. Any tips? [closed]

Guys really frustrated here. Spent many hours on this but can't seem to figure it out. I have attached my code below and the instructions after it. I keep getting no matching function to call x,y,z.

    using namespace std;

    // Function Prototypes
    
    const int NUM_CHARACTERS=8;
    char password[NUM_CHARACTERS]={'K','9','$','o','7','t','t','u'};
    bool validCharacter(char ch); /*take char as param and returns true if alphanum
    or ($, *, ^ , %). Else false*/
    char getValidCharacter(); /* to enter an alphanum char  and
    only ($, *, ^ , %)and loops until a valid char. it returns valid char*/
    void displayPassword(char password[NUM_CHARACTERS]);/*takes pass array as param and displays in
     correct format.*/
    void ChangePassword(char password[NUM_CHARACTERS]);/* takes pass array as a param,
    it allows to enter in NUM_CHARACTERS characters.
    stores each value  in pass array.*/
    void displayValidPassword(char password[NUM_CHARACTERS]);/*displays
    whether password is valid or not*/
    void DisplayMenuOptions();// Displays menu
    int SelectValidMenuOption();// choose correct option
    bool all_checked= false;
    char temp[NUM_CHARACTERS];
    int count=0;
    int specials=0;
    bool validPassword= true;
    bool nosymb=false;
     char special[]={'$','*','^','%'};




int main() {
    const int NUM_CHARACTERS =8; // password limit
    int menuCh=0;

    do {
        switch (menuCh)
        {
            case 1:
                displayPassword();
                break;
            case 2:
                ChangePassword(), getValidCharacter(), displayPassword();
                break;
        }
        cout << " Welcome to the Password Program\n";
    } while (menuCh !=4);

    return 0;
}













void displayValidPassword(char password[NUM_CHARACTERS])
{
    // password valid if there's one special and 2 numeric character
    // loop to check
     for (int p=0; p<NUM_CHARACTERS;p++)
     {
         if(!isalnum(password[p]))
             specials++;
     }
     for (int q=0; q<NUM_CHARACTERS;q++)
         if(isdigit(password[q]))
             count++;

     if(!special) nosymb= true;

     if (nosymb= false && count>=2 && specials >0)
         validPassword=true;
}







void displayPassword(char password[NUM_CHARACTERS])
{
cout<< password [NUM_CHARACTERS]<< endl;
}


void ChangePassword(char password[NUM_CHARACTERS])
{
cout<<"Enter your new password\n";
cin>> temp[NUM_CHARACTERS];
temp[NUM_CHARACTERS]=password[NUM_CHARACTERS];
}









bool ValidCharacter(char ch)
{
    if (isalnum(ch) != 0 || isalnum(ch) != 0 || isalnum(ch) != 0 ||
        isalnum(ch) != 0)
        return true;


}

  char getValidCharacter(char ch)
 {
        //user enter's password
        cout<<"Enter password\n";
        cin>>ch;
       // input validation
    {
            if (ValidCharacter(ch) ) all_checked= true;
            // prompt user
             if(!all_checked)
             cout << "Try again with valid characters( only alphanumeric and $,*,^,%)\n";
             cin>>ch;

    }
    return ch;

}
























void DisplayMenuOptions()
{
    cout<<"1) Display Password\n"<<"2) Change the password\n"
    <<"3) Display whether or not the password is valid\n"
    <<"4) Quit\n";
}

int SelectValidMenuOption()
{
    int menuCh;
    // get choice from user
    DisplayMenuOptions();
    cout<<"Enter in your choice:";
    cin>>menuCh;
    while ((menuCh<=1) ||(menuCh>4)) //input validation loop
    {

        // get choice from user
        DisplayMenuOptions();
        cout<<"Enter in your choice:";
        cin>>menuCh;
    }
    return menuCh;

Using the following array:

// may be declared outside the main function const int NUM_CHARACTERS =8;

// may only be declared within the main function char password[NUM_CHARACTERS]={'K','9','$','o','7','t','t','u'};

Be sure to compile using g++ -std=c++11 Password.cpp

Write a C++ program to run a menu-driven program with the following choices:

  1. Display the password

  2. Change the password

  3. Display whether or not the password is valid

  4. Quit Make sure your program conforms to the following requirements:

    Follow the course coding standards outlined in Coding Standards_ (COP3363 Introduction to Programming in C++ for Majors).docx

    .

You will lose 1 point for each coding standard violation.

This program should be called Password.cpp
Include the basic header in your program Header for Assignments.docx 

. (5 points deduction is missing)
Your solution must be built to allow the size of the array to change in the future without requiring any changes to your functions. You will lose points if you do not satisfy this requirement.
Write a function called validCharacter that takes a character as a parameter returns true if the character is an alphanumeric character or one of the following symbols ($, *, ^ , %) and false otherwise. (5 points).

bool validCharacter(char ch)

Write a function called getValidCharacter that allows a user to enter in an alphanumeric character or the following symbols ($, *, ^ , %)  and loops until a valid character is entered. It returns the valid character. (5 points).

char getValidCharacter();

Write a function called displayPassword that takes the password array as a parameter and displays the password in the format in the sample run below. (15 points).

void displayPassword(char password[NUM_CHARACTERS]);

Write a function called ChangePassword that takes the password array as a parameter, it allows the user to enter in NUM_CHARACTERS characters. It then stores each value entered in the password array. (20 points).

void ChangePassword(char password[NUM_CHARACTERS]);

Write a function called displayValidPassword that takes the password array as a parameter, it displays whether or not the password is valid. A valid password contains at least 1 special and 2 numeric characters.(20 points).

//displays whether or not the password is valid void displayValidPassword(char password[NUM_CHARACTERS]);

Aucun commentaire:

Enregistrer un commentaire