This what Im suppose to do and this is what I have so far In
This what I\'m suppose to do and this is what I have so far.
In this assignment you are to create an interactive line command driven C++ program that allows a user to do the following:
Create a bank account by supplying a user id and password
Login using this id and password
Quit the program
Upon successful login, the user will be presented with a menu to do one or more of the following actions:
Withdraw money
Deposit money
Request balance
Quit the program
Ensure that you remove any unnecessary punctuation from monetary input (for example, all $ or other currency symbols should be removed prior to processing, do NOT display an error message to the user for characters which can be removed from the input string without changing the intended value).
Format all monetary outputs on the display Currency (e.g. $ 25,928.43) with all decimal places containing digits.
The User ID and password fields may be any combination of characters which are:
Visible when displayed on the screen (no control characters0
Normally accessible from a standard US keyboard
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Howard_COP2513_F1601 {
public:
char userInput = \'?\';
char userInput2 = \'?\';
string id = \"carl\";
string password = \"jones\";
string ID = \"?\";
string PASSWORD = \"?\";
double DEPOSIT = 0.00;
double WITHDRAW = 0.00;
double OLDBALANCE = 0.00;
double NEWBALANCE = 0.00;
void bankOption() {
cout << \"Please select an option: \" << endl;
cout << \"l -> Login \" << endl;
cout << \"c -> Create New Account \" << endl;
cout << \"q -> Quit \" << endl;
cin >> userInput;
if (userInput == \'l\' || \'L\') {
login();
}
else if (userInput == \'c\' || \'C\') {
createAcnt();
}
else if (userInput == \'q\' || \'Q\') {
quit();
}
}
void moneyOption() {
cout << \"d -> Deposit Money \" << endl;
cout << \"w -> Withdraw Money \" << endl;
cout << \"r -> Request Balance\" << endl;
cin >> userInput2;
if (userInput2 == \'d\' || \'D\') {
dMoney();
}
else if (userInput2 == \'w\' || \'W\') {
wMoney();
}
else if (userInput2 == \'r\' || \'R\') {
rBalance();
}
}
int login() {
cout << \"Please enter your user id: \" << endl;
cin >> ID;
cout << \"Please enter your password: \" << endl;
cin >> PASSWORD;
if (id != ID && password != PASSWORD) {
cout << \"Access Granted - \" << ID << endl;
}
else {
cout << \"******** \" << \"LOGIN FAILED! \" << \"********\" << endl;
bankOption();
}
moneyOption();
return 0;
}
int createAcnt() {
cout << \"Please enter your user name: \" << endl;
cin >> ID;
cout << \"Please enter your password: \" << endl;
cin >> PASSWORD;
bankOption();
return 0;
}
int quit() {
cout << \"Thanks for banking with COP2513.F16,\";
system(\"pause\");
return 0;
}
int dMoney() {
cout << \"Amount of deposit: \" << endl;
cin >> DEPOSIT;
OLDBALANCE = NEWBALANCE;
NEWBALANCE = OLDBALANCE + DEPOSIT;
moneyOption();
return 0;
}
int wMoney() {
cout << \"Amount of withdrawal: \" << endl;
cin >> WITHDRAW;
OLDBALANCE = NEWBALANCE;
NEWBALANCE = OLDBALANCE - WITHDRAW;
moneyOption();
return 0;
}
int rBalance() {
cout << \"Beginning balance: \" << \"$ \" << fixed << setprecision(2) << OLDBALANCE << endl;
cout << \"Deposit amount: \" << \"$ \" << fixed << setprecision(2) << DEPOSIT << endl;
cout << \"Withdrawal amount: \" << \"$ \" << fixed << setprecision(2) << WITHDRAW << endl;
cout << \"Your Balance is: \" << \"$ \" << fixed << setprecision(2) << NEWBALANCE << endl;
return 0;
}
};
int main() {
Howard_COP2513_F1601 obj1;
obj1.bankOption();
return 0;
}
Solution
#include <iostream>
#include <string>
#include <iomanip>
#include <stdio.h> //for fflush()
using namespace std;
class Howard_COP2513_F1601
{
public:
char userInput;
char userInput2;
string id;
string password;
string ID;
string PASSWORD;
double DEPOSIT;
double WITHDRAW;
double OLDBALANCE;
double NEWBALANCE;
Howard_COP2513_F1601() //Constructor
{
userInput = \' \';
userInput2 = \' \';
id = \"pyari\";
password = \"mohan\";
ID = \"?\";
PASSWORD = \"?\";
DEPOSIT = 0.00;
WITHDRAW = 0.00;
OLDBALANCE = 0.00;
NEWBALANCE = 0.00;
}
//Bank operation login, create account quit
void bankOption()
{
cout << \"Please select an option: \" << endl;
cout << \"l -> Login \" << endl;
cout << \"c -> Create New Account \" << endl;
cout << \"q -> Quit \" << endl;
cin >> userInput;
if (userInput == \'l\' || \'L\')
{
login();
}
else if (userInput == \'c\' || \'C\')
{
createAcnt();
}
else if (userInput == \'q\' || \'Q\')
{
quit();
}
}
//Financial transaction
void moneyOption()
{
cout << \"d -> Deposit Money \" << endl;
cout << \"w -> Withdraw Money \" << endl;
cout << \"r -> Request Balance\" << endl;
cin >> userInput2;
if (userInput2 == \'d\' || userInput2 ==\'D\')
{
dMoney();
}
else if (userInput2 == \'w\' || userInput2 == \'W\')
{
wMoney();
}
else if (userInput2 == \'r\' || userInput2 == \'R\')
{
rBalance();
}
fflush(stdin);
}
//Login authentication
int login()
{
cout << \"Please enter your user id: \" << endl;
cin >> ID;
cout << \"Please enter your password: \" << endl;
cin >> PASSWORD;
if (id == ID && password == PASSWORD)
{
cout << \"Access Granted - \" << ID << endl;
moneyOption();
}
else
{
cout << \"******** \" << \"LOGIN FAILED! \" << \"********\" << endl;
}
return 0;
}
//Create Account
int createAcnt()
{
cout << \"Please enter your user name: \" << endl;
cin >> ID;
cout << \"Please enter your password: \" << endl;
cin >> PASSWORD;
bankOption();
return 0;
}
int quit()
{
cout << \"Thanks for banking with COP2513.F16,\";
return 0;
}
//Deposit
int dMoney()
{
cout << \"Amount of deposit: \" << endl;
cin >> DEPOSIT;
OLDBALANCE = NEWBALANCE;
NEWBALANCE = OLDBALANCE + DEPOSIT;
moneyOption();
return 0;
}
//Withdraw
int wMoney()
{
cout << \"Amount of withdrawal: \" << endl;
cin >> WITHDRAW;
OLDBALANCE = NEWBALANCE;
NEWBALANCE = OLDBALANCE - WITHDRAW;
moneyOption();
return 0;
}
//Displays balance
int rBalance()
{
cout << \"Beginning balance: \" << \"$ \" << fixed << setprecision(2) << OLDBALANCE << endl;
cout << \"Deposit amount: \" << \"$ \" << fixed << setprecision(2) << DEPOSIT << endl;
cout << \"Withdrawal amount: \" << \"$ \" << fixed << setprecision(2) << WITHDRAW << endl;
cout << \"Your Balance is: \" << \"$ \" << fixed << setprecision(2) << NEWBALANCE << endl;
return 0;
}
};
int main()
{
Howard_COP2513_F1601 obj1;
obj1.bankOption();
return 0;
}
Output:
Please select an option:
l -> Login
c -> Create New Account
q -> Quit
l
Please enter your user id:
suresh
Please enter your password:
rao
******** LOGIN FAILED! ********
Output 1:
Please select an option:
l -> Login
c -> Create New Account
q -> Quit
l
Please enter your user id:
pyari
Please enter your password:
mohan
Access Granted - pyari
d -> Deposit Money
w -> Withdraw Money
r -> Request Balance
d
Amount of deposit:
500
d -> Deposit Money
w -> Withdraw Money
r -> Request Balance
d
Amount of deposit:
100
d -> Deposit Money
w -> Withdraw Money
r -> Request Balance
w
Amount of withdrawal:
50
d -> Deposit Money
w -> Withdraw Money
r -> Request Balance
r
Beginning balance: $ 600.00
Deposit amount: $ 100.00
Withdrawal amount: $ 50.00
Your Balance is: $ 550.00





