#include #include #include using namespace std; bool validate_name(const string &name) { for(auto c: name) { if(!(c>=97 && c<=122) && !(c>=65 && c<=90) && c!=' ') return false; } return true; } void title_case(string &name) { if(name.empty()) return; name[0] = toupper(name[0]); for(int i {1}; i> account_num; cin.ignore(numeric_limits::max(),'\n'); if(validate_account(account_num)) break; else cout << "Your account number is a 6-digit number. Enter again:" << endl; } int choice {0}; float b_penalty {0}; char cont = ' '; while(tolower(cont)!='n') { while (true) { cout << "What is your account type? 0

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Can someone give write out a simple step by step algorithm for this code... (explain how you would using //)

 

 

#include<iostream>
#include <string>
#include<limits>

using namespace std;

bool validate_name(const string &name) {
for(auto c: name) {
if(!(c>=97 && c<=122) && !(c>=65 && c<=90) && c!=' ')
return false;
}
return true;
}

void title_case(string &name) {
if(name.empty())
return;
name[0] = toupper(name[0]);
for(int i {1}; i<name.size(); ++i) {
if(name[i] == ' ') {
name[i+1] = toupper(name[i+1]);
}
}
}

bool validate_account(long num) {
int count {0};
while(num!=0) {
++count;
num /= 10;
}
return count == 6;
}

int main() {
const float b_min_bal = 10000.00;
const float p_min_bal = 1000.00;
float b_cur_bal = 10000.00;
float p_cur_bal = 1000.00;
enum account {Business=0, Personal=1};
string name;
while(true) {
cout << "Enter you name: ";
getline(cin, name);
if(validate_name(name))
break;
else cout << "Your name can only have alphabets or spaces. Enter again." << endl;
}
title_case(name);
long account_num {0};
cout << "Enter your account number: ";
while(true) {
cin >> account_num;
cin.ignore(numeric_limits<streamsize>::max(),'\n');
if(validate_account(account_num))
break;
else cout << "Your account number is a 6-digit number. Enter again:" << endl;
}
int choice {0};
float b_penalty {0};
char cont = ' ';
while(tolower(cont)!='n') {
while (true) {
cout << "What is your account type? 0 for Business, 1 for Personal: ";
cin >> choice;
cin.ignore(numeric_limits<streamsize>::max(),'\n');
if (choice != 0 && choice != 1)
cout << "Wrong choice. Please enter again." << endl;
else break;
}
account acc = choice == 0 ? Business : Personal;
switch (acc) {
case Business: {
float transaction{0};
cout << "Enter transaction: ";
cin >> transaction;
cin.ignore(numeric_limits<streamsize>::max(),'\n');
if (b_penalty > 0) {
cout << "Your balance is less than the required minimum."
<< "There will be a $10.00 fee for every transaction." << endl;
b_cur_bal -= b_penalty;
}
b_cur_bal += transaction;
b_penalty = b_cur_bal < b_min_bal ? 10 : 0;
cout << "Business Balance: $" << b_cur_bal << endl;
}
break;
case Personal: {
float transaction{0};
cout << "Enter transaction: ";
cin >> transaction;
cin.ignore(numeric_limits<streamsize>::max(),'\n');
p_cur_bal += transaction;
if(p_cur_bal < p_min_bal) {
cout << "Your personal balance cannot be less than minimum balance." << endl;
cout << "Transaction denied" << endl;
p_cur_bal = p_min_bal;
}
cout << "Personal Balance: $" << p_cur_bal << endl;
}
break;
}
cout << "Do you want to process another transaction? Y/N: ";
while(true) {
cin >> cont;
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cont = tolower(cont);
if(cont == 'n' || cont == 'y')
break;
else cout << "Wong choice. Enter Y/N: ";
}
}
cout << "Name: " << name << endl;
cout << "Account Number (Encrypted): " << account_num << endl;
cout << "Business Balance: $" << b_cur_bal << endl;
cout << "Personal Balance: $" << p_cur_bal << endl;

return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY