#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
Can someone give write out a simple step by step
#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;
}
Step by step
Solved in 2 steps with 1 images