简体   繁体   English

我将如何检查 main 中的布尔变量,以便我的 do-while 循环遍历三个函数?

[英]How would i check the boolean variable in main so my do-while loop goes through the three functions?

Okay so my problem is I can't seem to find or think of anything that will go into the while argument that will check all three functions to see if each one is false please help!好的,所以我的问题是我似乎无法找到或想到会进入 while 参数的任何内容,该参数将检查所有三个函数以查看每个函数是否为假,请帮助! That is my problem!那是我的问题!

class Validate
{
public: 
    Validate(string);
     Validate();
    bool checkLength();
    bool checkSpaces();
    bool checkUpper();
    //bool checkUpper(char);
private:
    string password;
    static const int LEN = 5;

};
Validate::Validate()
{

}
Validate::Validate(string pass)
{
    pass = password;

}
bool Validate:: checkLength()
{
        if (password.length() < LEN)
        {
            cout << "Password is not 5 characters." << "  please try again..." << endl;
            return true;
        }
        else 
            return false;

}
bool Validate::checkSpaces()
{
    if (password.find(' ') != string::npos)
    {
        cout << "Password can not have any spaces " << endl;
        return true;
    }
    else
        return false;
}
bool Validate::checkUpper()
{

    for (int i = 0; i < password.length(); i++)
    {
        if (!isupper(password[i]))
        {
            cout << "Password must have at least one uppercase" << endl;
            return true;
        }
        else
            return false;
    }



}

Main file主文件

//DISPLAY 8.9 Using a Vector
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#include "c:\Users\barta\OneDrive\Documents\Visual Studio 2015\Projects\Project 7\Project 7\Validate.h"

int main( )
{

    vector<string> data;
    string firstName, lastName, login, userName, password;
    Validate c;
    bool check;
    firstName = "1";

    cout << "Enter your first name.\n";
    getline(cin, firstName);
    while (firstName != "0")
    {

        cout << "Enter your last name.\n";
        getline(cin, lastName);
        do
        {

            cout << "Enter a password.\n";
            getline(cin, password);
            //password = c.checkLength();
            //password = c.checkSpaces();
            c.checkUpper();

        } while (false);

        lastName = lastName.substr(0, 5);

        userName = firstName.at(0) + lastName;
        login = userName + ", " + password;
        data.push_back(login);

        cout << "Enter your first name.\n";
        getline(cin, firstName);
    }

    cout << "  Login data entered \n" << endl;

        for (unsigned int i = 0; i < data.size(); i++)
        {
            cout << "  " << data.at(i) << endl;
        }



    system("pause");
    return 0;
}

Your question is slightly unclear, but I think you're looking for:您的问题有点不清楚,但我认为您正在寻找:

 bool flag;

 do
 {
        // All your existing code is here...

        Validate c{password};

        flag = c.checkLength() || c.checkSpaces() || c.checkUpper();

 } while (flag);

Your Validate class's constructor takes the password as a parameter, so you have to construct the object after the password is read, and not at the beginning of main() .您的Validate类的构造函数将密码作为参数,因此您必须在读取密码后构造对象,而不是在main()的开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM