C++ Banking ClassFormatter classC++ Kernel Factory classC++ Class Writing Interview QueryGPIO wrapper classPolynomial classGeneric object pool classSchool Banking ProjectBrute force string generation and password cracking in C++An account/banking system in C++C++ writing object data to file

Why is consensus so controversial in Britain?

What does the expression "A Mann!" means

Is it inappropriate for a student to attend their mentor's dissertation defense?

How do conventional missiles fly?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

What does “the session was packed” mean in this context?

Why do bosons tend to occupy the same state?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

Avoiding direct proof while writing proof by induction

Is there a hemisphere-neutral way of specifying a season?

How dangerous is XSS?

How to prevent "they're falling in love" trope

What is the most common color to indicate the input-field is disabled?

Is it logically or scientifically possible to artificially send energy to the body?

What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"

Determining Impedance With An Antenna Analyzer

How much of data wrangling is a data scientist's job?

Examples of smooth manifolds admitting inbetween one and a continuum of complex structures

Detention in 1997

How can saying a song's name be a copyright violation?

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

Do scales need to be in alphabetical order?

Can I run a new neutral wire to repair a broken circuit?

How could indestructible materials be used in power generation?



C++ Banking Class


Formatter classC++ Kernel Factory classC++ Class Writing Interview QueryGPIO wrapper classPolynomial classGeneric object pool classSchool Banking ProjectBrute force string generation and password cracking in C++An account/banking system in C++C++ writing object data to file













0












$begingroup$


I'm currently self-teaching myself C++, using a C++ For Dummies book that I bought a couple months ago. To practice, I've created a Bank class that holds usernames and passwords, and that has a login/logout system. IT also implements a failsafe if there are too many failed login attempts. I'm looking for advice that can help make this code better, i.e more efficient, more compact, and more up-to-date with todays C++ standards. Any and all help is appreciated and considered.



bank.cpp



//Include Statements
#include <iostream>
#include <vector>
#include <string>

//Class Body
class Bank

std::vector<std::string> usernames;
std::vector<std::string> passwords;
std::string user;
int attempts;
bool lockedOut;

public:
bool login(std::string username, std::string password);
void logout();
std::string getCurrentUser();
//Constructor
Bank()
generateTestAccounts();
attempts = 0;
lockedOut = false;


private:
void generateTestAccounts();

;

//Class Functions

/*
* Checks if a user is not logged in, and if not, checks to see if
* the passed username and password match any in the Bank
*/
bool Bank::login(std::string username, std::string password)
if(!lockedOut)
if(user.empty())
for(int i = 0; i < usernames.size(); i++)
if(usernames[i].compare(username) == 0)
user = username;
return true;



attempts += 1;
if(attempts == 3)
lockedOut = true;


return false;



/*
* Logs out the current user by clearing the string value from `user`
*/
void Bank::logout()
user.clear(); //basically null


/*
* Returns the currently logged in user
*/
std::string Bank::getCurrentUser()
return user;
;

/*
* Generates test accounts that can be used to make sure the
* `login` method works
*/
void Bank::generateTestAccounts()
for(int i = 0; i < 5; i++)
usernames.push_back("user" + std::to_string(i));
passwords.push_back("pass" + std::to_string(i));



/*
* main method for testing bank class
*/
int main()
Bank bank;
std::string us = "user1";
std::string pw = "pass1";
if(bank.login(us, pw))
std::cout << "Logged in as " + us << std::endl;










share









$endgroup$
















    0












    $begingroup$


    I'm currently self-teaching myself C++, using a C++ For Dummies book that I bought a couple months ago. To practice, I've created a Bank class that holds usernames and passwords, and that has a login/logout system. IT also implements a failsafe if there are too many failed login attempts. I'm looking for advice that can help make this code better, i.e more efficient, more compact, and more up-to-date with todays C++ standards. Any and all help is appreciated and considered.



    bank.cpp



    //Include Statements
    #include <iostream>
    #include <vector>
    #include <string>

    //Class Body
    class Bank

    std::vector<std::string> usernames;
    std::vector<std::string> passwords;
    std::string user;
    int attempts;
    bool lockedOut;

    public:
    bool login(std::string username, std::string password);
    void logout();
    std::string getCurrentUser();
    //Constructor
    Bank()
    generateTestAccounts();
    attempts = 0;
    lockedOut = false;


    private:
    void generateTestAccounts();

    ;

    //Class Functions

    /*
    * Checks if a user is not logged in, and if not, checks to see if
    * the passed username and password match any in the Bank
    */
    bool Bank::login(std::string username, std::string password)
    if(!lockedOut)
    if(user.empty())
    for(int i = 0; i < usernames.size(); i++)
    if(usernames[i].compare(username) == 0)
    user = username;
    return true;



    attempts += 1;
    if(attempts == 3)
    lockedOut = true;


    return false;



    /*
    * Logs out the current user by clearing the string value from `user`
    */
    void Bank::logout()
    user.clear(); //basically null


    /*
    * Returns the currently logged in user
    */
    std::string Bank::getCurrentUser()
    return user;
    ;

    /*
    * Generates test accounts that can be used to make sure the
    * `login` method works
    */
    void Bank::generateTestAccounts()
    for(int i = 0; i < 5; i++)
    usernames.push_back("user" + std::to_string(i));
    passwords.push_back("pass" + std::to_string(i));



    /*
    * main method for testing bank class
    */
    int main()
    Bank bank;
    std::string us = "user1";
    std::string pw = "pass1";
    if(bank.login(us, pw))
    std::cout << "Logged in as " + us << std::endl;










    share









    $endgroup$














      0












      0








      0





      $begingroup$


      I'm currently self-teaching myself C++, using a C++ For Dummies book that I bought a couple months ago. To practice, I've created a Bank class that holds usernames and passwords, and that has a login/logout system. IT also implements a failsafe if there are too many failed login attempts. I'm looking for advice that can help make this code better, i.e more efficient, more compact, and more up-to-date with todays C++ standards. Any and all help is appreciated and considered.



      bank.cpp



      //Include Statements
      #include <iostream>
      #include <vector>
      #include <string>

      //Class Body
      class Bank

      std::vector<std::string> usernames;
      std::vector<std::string> passwords;
      std::string user;
      int attempts;
      bool lockedOut;

      public:
      bool login(std::string username, std::string password);
      void logout();
      std::string getCurrentUser();
      //Constructor
      Bank()
      generateTestAccounts();
      attempts = 0;
      lockedOut = false;


      private:
      void generateTestAccounts();

      ;

      //Class Functions

      /*
      * Checks if a user is not logged in, and if not, checks to see if
      * the passed username and password match any in the Bank
      */
      bool Bank::login(std::string username, std::string password)
      if(!lockedOut)
      if(user.empty())
      for(int i = 0; i < usernames.size(); i++)
      if(usernames[i].compare(username) == 0)
      user = username;
      return true;



      attempts += 1;
      if(attempts == 3)
      lockedOut = true;


      return false;



      /*
      * Logs out the current user by clearing the string value from `user`
      */
      void Bank::logout()
      user.clear(); //basically null


      /*
      * Returns the currently logged in user
      */
      std::string Bank::getCurrentUser()
      return user;
      ;

      /*
      * Generates test accounts that can be used to make sure the
      * `login` method works
      */
      void Bank::generateTestAccounts()
      for(int i = 0; i < 5; i++)
      usernames.push_back("user" + std::to_string(i));
      passwords.push_back("pass" + std::to_string(i));



      /*
      * main method for testing bank class
      */
      int main()
      Bank bank;
      std::string us = "user1";
      std::string pw = "pass1";
      if(bank.login(us, pw))
      std::cout << "Logged in as " + us << std::endl;










      share









      $endgroup$




      I'm currently self-teaching myself C++, using a C++ For Dummies book that I bought a couple months ago. To practice, I've created a Bank class that holds usernames and passwords, and that has a login/logout system. IT also implements a failsafe if there are too many failed login attempts. I'm looking for advice that can help make this code better, i.e more efficient, more compact, and more up-to-date with todays C++ standards. Any and all help is appreciated and considered.



      bank.cpp



      //Include Statements
      #include <iostream>
      #include <vector>
      #include <string>

      //Class Body
      class Bank

      std::vector<std::string> usernames;
      std::vector<std::string> passwords;
      std::string user;
      int attempts;
      bool lockedOut;

      public:
      bool login(std::string username, std::string password);
      void logout();
      std::string getCurrentUser();
      //Constructor
      Bank()
      generateTestAccounts();
      attempts = 0;
      lockedOut = false;


      private:
      void generateTestAccounts();

      ;

      //Class Functions

      /*
      * Checks if a user is not logged in, and if not, checks to see if
      * the passed username and password match any in the Bank
      */
      bool Bank::login(std::string username, std::string password)
      if(!lockedOut)
      if(user.empty())
      for(int i = 0; i < usernames.size(); i++)
      if(usernames[i].compare(username) == 0)
      user = username;
      return true;



      attempts += 1;
      if(attempts == 3)
      lockedOut = true;


      return false;



      /*
      * Logs out the current user by clearing the string value from `user`
      */
      void Bank::logout()
      user.clear(); //basically null


      /*
      * Returns the currently logged in user
      */
      std::string Bank::getCurrentUser()
      return user;
      ;

      /*
      * Generates test accounts that can be used to make sure the
      * `login` method works
      */
      void Bank::generateTestAccounts()
      for(int i = 0; i < 5; i++)
      usernames.push_back("user" + std::to_string(i));
      passwords.push_back("pass" + std::to_string(i));



      /*
      * main method for testing bank class
      */
      int main()
      Bank bank;
      std::string us = "user1";
      std::string pw = "pass1";
      if(bank.login(us, pw))
      std::cout << "Logged in as " + us << std::endl;








      c++





      share












      share










      share



      share










      asked 1 min ago









      David WhiteDavid White

      334416




      334416




















          0






          active

          oldest

          votes












          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216829%2fc-banking-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216829%2fc-banking-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          कुँवर स्रोत दिक्चालन सूची"कुँवर""राणा कुँवरके वंशावली"

          Why is a white electrical wire connected to 2 black wires?How to wire a light fixture with 3 white wires in box?How should I wire a ceiling fan when there's only three wires in the box?Two white, two black, two ground, and red wire in ceiling box connected to switchWhy is there a white wire connected to multiple black wires in my light box?How to wire a light with two white wires and one black wireReplace light switch connected to a power outlet with dimmer - two black wires to one black and redHow to wire a light with multiple black/white/green wires from the ceiling?Ceiling box has 2 black and white wires but fan/ light only has 1 of eachWhy neutral wire connected to load wire?Switch with 2 black, 2 white, 2 ground and 1 red wire connected to ceiling light and a receptacle?

          चैत्य भूमि चित्र दीर्घा सन्दर्भ बाहरी कडियाँ दिक्चालन सूची"Chaitya Bhoomi""Chaitya Bhoomi: Statue of Equality in India""Dadar Chaitya Bhoomi: Statue of Equality in India""Ambedkar memorial: Centre okays transfer of Indu Mill land"चैत्यभमि