dilshod-obidov / oop Goto Github PK
View Code? Open in Web Editor NEWObject Oriented Programming
Object Oriented Programming
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;
}
}
void AccountHandler::ShowAllAccInfo(void) const{
int i = 0;
for(int i=0; i<m_accNum; i++){
if (m_accArr[i] != NULL) {
m_accArr[i]->ShowAccInfo();
i++;
}
}
if (i == 0) {
cout << "There is no existing account." << endl;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.