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
$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;
c++
$endgroup$
add a comment |
$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;
c++
$endgroup$
add a comment |
$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;
c++
$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++
c++
asked 1 min ago
David WhiteDavid White
334416
334416
add a comment |
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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