Giter Club home page Giter Club logo

oop's People

Contributors

dilshod-obidov avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

elee02

oop's Issues

Logic of the bool AccountHandler::Confirm() const; function can lead to unwanted behavior.

The potential issue with the piece of code below is that it doesn't handle unexpected input gracefully. If the user enters anything other than "y", the function will return false. This includes cases where the user might enter "yes", "Y", or any other potential affirmative response.

Additionally, if the user enters multiple words or characters, only the first one will be read due to the use of cin >> ans;, which could lead to unexpected behavior.

Here's a more robust version of the function:

bool AccountHandler::Confirm(void) const {
    string ans;
    cout << "Are you sure? (y/n) ";
    getline(cin, ans);
    
    if (ans == "y" || ans == "Y" || ans == "yes" || ans == "Yes" || ans == "YES") {
        return true;
    }
    else {
        return false;
    }
}

This version uses getline(cin, ans); to read the entire line of input. It then checks if the input is either "y" or "yes".

More robust versions of this function could be written to handle more cases, but this is a good start:

bool AccountHandler::Confirm(void) const {
    string ans;
    cout << "Are you sure? (y/n) ";
    getline(cin, ans);
    transform(ans.begin(), ans.end(), ans.begin(), ::tolower);
    if (ans == "y" || ans == "yes") {
        return true;
    }
    else {
        return false;
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.