Title: Simple Banking Record (In C++ please) Learning objectives: 1. Use of func
ID: 3885158 • Letter: T
Question
Title: Simple Banking Record (In C++ please)
Learning objectives:
1. Use of functions
2. Use of loops and if statement
3. Use of arrays and pointers
Lab Objective: Part 1
Write a program that will be used by a bank clerk to create a client's account and will then allow the clerk to enter withdraws and deposits on that account. The program should offer the ability for the clerk to view the current balance on the account.
Sample run of the program:
At startup the clerk will get a menu:
MAIN MENU
==========
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
Enter your choice:_
If the clerk chooses option 1:
The program will ask to enter an account number and full name;
The program will then return to the main menu.
If the clerk chooses option 2:
The program must first check if the client exists. An appropriate error should display and the program goes back to the main menu.
If a client exists, the program will offer the choice of withdraw or deposit. The program must inspect the balance for overdraft.
If the clerk chooses option 3:
The program will display the account number, the full name and the balance.
Option: exit the program completely!
Part 2: A client can have more than one account. Typically a client would have a checking and a savings account. Rewrite another version of the previous program to accommodate for this feature.
Part 3: This new version of the program will have all of the above features in addition to the ability of applying them to several clients.
Part 4: Make the data persistent. In other words, save all client information for later retrieval.
Explanation / Answer
Part 1
C++ code:
#include <bits/stdc++.h>
using namespace std;
struct info
{
string name;
int savings_account_balace = 0;
// int checking_account_balace;
};
map<int, info> data;
void addclient()
{
int account_no;
cout << "Enter the account number for adding new client" << endl;
cin >> account_no;
while(true)
{
if(data.find(account_no) == data.end())
{
string tmp_name; int tmp_bal;
cout << "Enter name of the client" << endl;
cin >> tmp_name;
cout << "Enter starting balance of client" << endl;
cin >> tmp_bal;
info tmp;
tmp.name = tmp_name; tmp.savings_account_balace = tmp_bal;
data[account_no] = tmp;
cout << "Savings account created successfully! " << endl;
break;
}
else
{
cout << "This account number allready exists, please enter new account number! ";
}
}
}
void balance()
{
cout << "Enter the account number of the client! ";
int account_no;
cin >> account_no;
if(data.find(account_no) == data.end())
{
cout << "This account does not exists, please enter correct account number! ";
}
else
{
cout << "Account details ";
info tmp = data[account_no];
cout << "Account number: " << account_no << " ";
cout << "Client Name: " << tmp.name << endl;
cout << "Balance: " << tmp.savings_account_balace << endl<< endl;
}
}
void transaction()
{
cout << "Enter 1 for Withdraw and 2 for Deposit ";
int c;
cin >> c;
if(c == 1)
{
cout << "Enter the account number to Withdraw money! " << endl;
int account_no;
cin >> account_no;
if(data.find(account_no) == data.end())
{
cout << "This account does not exists, please enter correct account number! ";
}
else
{
cout << "Enter the amount to Withdraw! " << endl;
int tmp_widr;
cin >> tmp_widr;
info tmp = data[account_no];
if(tmp.savings_account_balace >= tmp_widr)
{
data[account_no].savings_account_balace = data[account_no].savings_account_balace - tmp_widr;
cout << "Your transaction is successfull!" << "New balance available = " << data[account_no].savings_account_balace << endl<< endl<< endl;
}
else
{
cout << "Insufficient balance in your account, can not process this transaction !" << endl;
}
}
}
else if(c == 2)
{
cout << "Enter the account number to Deposit money!" << endl;
int account_no;
cin >> account_no;
if(data.find(account_no) == data.end())
{
cout << "This account does not exists, please enter correct account number! ";
}
else
{
cout << "Enter the amount to Deposit!" << endl;
int tmp_dep;
cin >> tmp_dep;
info tmp = data[account_no];
if(tmp_dep > 0)
{
data[account_no].savings_account_balace = data[account_no].savings_account_balace + tmp_dep;
cout << "Your transaction is successfull!" << "New balance available = " << data[account_no].savings_account_balace << endl<< endl<< endl;
}
else
{
cout << "Invalid Deposit amount, Enter positive ammount! " << endl;
}
}
}
else
{
cout << "Wrong input! Enter 1 or 2!" << endl;
}
}
int main()
{
while(true)
{
cout << "1. Add a client account 2. Apply transactions on the client account 3. View the balance 4. Exit ";
int c;
cin >> c;
if(c == 1)
{
addclient();
}
else if(c == 2)
{
transaction();
}
else if(c == 3)
{
balance();
}
else if(c == 4)
{
exit(0);
}
else
{
cout << "Invalid input" << endl;
}
}
return 0;
}
Sample Output:
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
1
Enter the account number for adding new client
1111
Enter name of the client
john
Enter starting balance of client
1000
Savings account created successfully!
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
3
Enter the account number of the client!
1111
Account details
Account number: 1111
Client Name: john
Balance: 1000
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
2
Enter 1 for Withdraw and 2 for Deposit
1
Enter the account number to Withdraw money!
1111
Enter the amount to Withdraw!
500
Your transaction is successfull!New balance available = 500
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
2
Enter 1 for Withdraw and 2 for Deposit
2
Enter the account number to Deposit money!
1111
Enter the amount to Deposit!
250
Your transaction is successfull!New balance available = 750
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
3
Enter the account number of the client!
1111
Account details
Account number: 1111
Client Name: john
Balance: 750
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
4
Part 2/3/4
C++ code:
#include <bits/stdc++.h>
using namespace std;
struct info
{
string name;
int balance = 0;
int issavingsaccount = 1; //by default account will be savings other wise it will be checking
};
map<int, info> data;
void addclient()
{
cout << "Enter 1 if you want to create savings account, other wise enter 2! ";
int c ;
cin >> c;
int account_no;
cout << "Enter the account number for adding new client" << endl;
cin >> account_no;
while(true)
{
if(data.find(account_no) == data.end())
{
string tmp_name; int tmp_bal;
cout << "Enter name of the client" << endl;
cin >> tmp_name;
cout << "Enter starting balance of client" << endl;
cin >> tmp_bal;
info tmp;
tmp.name = tmp_name; tmp.balance = tmp_bal;
if(c == 1)
{
tmp.issavingsaccount = 1;
}
else
{
tmp.issavingsaccount = 0;
}
data[account_no] = tmp;
if(tmp.issavingsaccount == 1)
{
cout << "Savings account created successfully! " << endl;
}
else
{
cout << "checking account created successfully! " << endl;
}
break;
}
else
{
cout << "This account number allready exists, please enter new account number! ";
}
}
}
void balance()
{
cout << "Enter the account number of the client! ";
int account_no;
cin >> account_no;
if(data.find(account_no) == data.end())
{
cout << "This account does not exists, please enter correct account number! ";
}
else
{
cout << "Account details ";
info tmp = data[account_no];
cout << "Account number: " << account_no << " ";
cout << "Client Name: " << tmp.name << endl;
if(tmp.issavingsaccount == 1)
{
cout << "Account Type: Savings account" << endl;
}
else
{
cout << "Account Type: Checking account" << endl;
}
cout << "Balance: " << tmp.balance << endl<< endl;
}
}
void transaction()
{
cout << "Enter 1 for Withdraw and 2 for Deposit ";
int c;
cin >> c;
if(c == 1)
{
cout << "Enter the account number to Withdraw money! " << endl;
int account_no;
cin >> account_no;
if(data.find(account_no) == data.end())
{
cout << "This account does not exists, please enter correct account number! ";
}
else
{
cout << "Enter the amount to Withdraw! " << endl;
int tmp_widr;
cin >> tmp_widr;
info tmp = data[account_no];
if(tmp.balance >= tmp_widr)
{
data[account_no].balance = data[account_no].balance - tmp_widr;
cout << "Your transaction is successfull!" << "New balance available = " << data[account_no].balance << endl<< endl<< endl;
}
else
{
cout << "Insufficient balance in your account, can not process this transaction !" << endl;
}
}
}
else if(c == 2)
{
cout << "Enter the account number to Deposit money!" << endl;
int account_no;
cin >> account_no;
if(data.find(account_no) == data.end())
{
cout << "This account does not exists, please enter correct account number! ";
}
else
{
cout << "Enter the amount to Deposit!" << endl;
int tmp_dep;
cin >> tmp_dep;
info tmp = data[account_no];
if(tmp_dep > 0)
{
data[account_no].balance = data[account_no].balance + tmp_dep;
cout << "Your transaction is successfull!" << "New balance available = " << data[account_no].balance << endl<< endl<< endl;
}
else
{
cout << "Invalid Deposit amount, Enter positive ammount! " << endl;
}
}
}
else
{
cout << "Wrong input! Enter 1 or 2!" << endl;
}
}
int main()
{
while(true)
{
cout << "1. Add a client account 2. Apply transactions on the client account 3. View the balance 4. Exit ";
int c;
cin >> c;
if(c == 1)
{
addclient();
}
else if(c == 2)
{
transaction();
}
else if(c == 3)
{
balance();
}
else if(c == 4)
{
exit(0);
}
else
{
cout << "Invalid input" << endl;
}
}
return 0;
}
Sample Output:
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
1
Enter 1 if you want to create savings account, other wise enter 2!
1
Enter the account number for adding new client
1111
Enter name of the client
john
Enter starting balance of client
1000
Savings account created successfully!
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
1
Enter 1 if you want to create savings account, other wise enter 2!
2
Enter the account number for adding new client
2222
Enter name of the client
Ben
Enter starting balance of client
1000
checking account created successfully!
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
2
Enter 1 for Withdraw and 2 for Deposit
1
Enter the account number to Withdraw money!
1111
Enter the amount to Withdraw!
5000
Insufficient balance in your account, can not process this transaction
!
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
3
Enter the account number of the client!
1111
Account details
Account number: 1111
Client Name: john
Account Type: Savings account
Balance: 1000
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
2
Enter 1 for Withdraw and 2 for Deposit
1
Enter the account number to Withdraw money!
1111
Enter the amount to Withdraw!
500
Your transaction is successfull!New balance available = 500
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
2
Enter 1 for Withdraw and 2 for Deposit
2
Enter the account number to Deposit money!
2222
Enter the amount to Deposit!
500
Your transaction is successfull!New balance available = 1500
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
3
Enter the account number of the client!
1111
Account details
Account number: 1111
Client Name: john
Account Type: Savings account
Balance: 500
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
3
Enter the account number of the client!
2222
Account details
Account number: 2222
Client Name: Ben
Account Type: Checking account
Balance: 1500
1. Add a client account
2. Apply transactions on the client account
3. View the balance
4. Exit
4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.