-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6648e39
commit 30ecc14
Showing
5 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
1 | ||
Yusuf | ||
Salaudeen | ||
25000 | ||
2 | ||
Zainab | ||
Akande | ||
3000 | ||
3 | ||
Jim | ||
Rohn | ||
10000 | ||
4 | ||
Kylian | ||
Mbappe | ||
12000 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include "banking.h" | ||
|
||
// Account class implementation | ||
|
||
long Account::nextActNum_ = 0; | ||
Account::Account(string firstName, string lastName, double bal){ | ||
firstName_ = firstName; | ||
lastName_ = lastName; | ||
bal_ = bal; | ||
nextActNum_++; | ||
actNum_ = nextActNum_; | ||
} | ||
|
||
// accesors | ||
double Account::bal() { return bal_; } | ||
long Account::actNum() { return actNum_; } | ||
string Account::firstName() { return firstName_; } | ||
string Account::lastName() { return lastName_; } | ||
|
||
// manipulators | ||
void Account::deposit(double amount){ bal_ += amount; } | ||
void Account::withdraw(double amount){ | ||
if (bal_ - amount < minimum_bal) { | ||
throw InsufficientFunds(); | ||
} | ||
bal_-=amount; | ||
} | ||
void Account::lastActNum(long actNum){ nextActNum_ = actNum; } | ||
long Account::lastActNum(){ return nextActNum_; } | ||
|
||
ofstream &operator << (ofstream &ofs, Account &account){ | ||
ofs <<account.actNum_ << endl; | ||
ofs << account.firstName_ << endl; | ||
ofs << account.lastName_ << endl; | ||
ofs << account.bal_ << endl; | ||
return ofs; | ||
} | ||
ifstream &operator >> (ifstream &ifs, Account &account){ | ||
ifs >> account.actNum_; | ||
ifs >> account.firstName_; | ||
ifs >> account.lastName_; | ||
ifs >> account.bal_; | ||
return ifs; | ||
} | ||
ostream &operator << (ostream &os, Account &account){ | ||
os << "First Name: " << account.firstName() << endl; | ||
os << "Last Name: " << account.lastName() << endl; | ||
os << "Account Number: " << account.actNum() << endl; | ||
os << "Balance: " << account.bal() << endl; | ||
return os; | ||
} | ||
|
||
// Bank class implementation | ||
|
||
Bank::Bank(){ | ||
Account account; | ||
ifstream infile; | ||
infile.open("Bank.data"); | ||
if(!infile){ | ||
//cout << "Error in opening, file not found!\n"; | ||
return; | ||
} | ||
while(!infile.eof()){ | ||
infile >> account; | ||
pair<long, Account> entry; | ||
entry = make_pair(account.actNum(), account); | ||
accounts.insert(entry); | ||
|
||
// == accounts.insert(pair<long, Account>(account.actNum(), account)); | ||
} | ||
Account::lastActNum(account.actNum()); | ||
infile.close(); | ||
} | ||
|
||
Account Bank::openAct(string firstName, string lastName, double bal){ | ||
ofstream outfile; | ||
Account account(firstName, lastName, bal); | ||
accounts.insert(pair<long, Account>(account.actNum(), account)); | ||
|
||
outfile.open("Bank.data", ios::trunc); | ||
|
||
map<long, Account>::iterator itr; | ||
for(itr = accounts.begin(); itr != accounts.end(); itr++){ | ||
outfile << itr->second; | ||
} | ||
outfile.close(); | ||
return account; | ||
} | ||
|
||
Account Bank::balanceEnquiry(long actNum){ | ||
map<long, Account>::iterator itr; | ||
itr = accounts.find(actNum); | ||
return itr->second; | ||
} | ||
Account Bank::deposit(long actNum, double amount){ | ||
map<long, Account>::iterator itr; | ||
itr = accounts.find(actNum); | ||
itr->second.deposit(amount); | ||
return itr->second; | ||
} | ||
Account Bank::withdraw(long actNum, double amount){ | ||
map<long, Account>::iterator itr; | ||
itr = accounts.find(actNum); | ||
itr->second.withdraw(amount); | ||
return itr->second; | ||
} | ||
void Bank::closeAccount(long actNum){ | ||
map<long, Account>::iterator itr; | ||
itr = accounts.find(actNum); | ||
cout << "Account deleted.\n"; | ||
accounts.erase(actNum); | ||
} | ||
void Bank::showAllAccounts(){ | ||
map<long, Account>::iterator itr; | ||
for (itr = accounts.begin(); itr != accounts.end(); itr++){ | ||
cout << "Account " << itr->first << endl << itr->second << endl; | ||
} | ||
} | ||
Bank::~Bank(){ | ||
ofstream outfile; | ||
outfile.open("Bank.data", ios::trunc); | ||
|
||
map<long, Account>::iterator itr; | ||
for (itr = accounts.begin(); itr != accounts.end(); itr++){ | ||
outfile << itr->second; | ||
} | ||
outfile.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <map> | ||
#include <cstdlib> | ||
#include <iterator> | ||
|
||
using namespace std; | ||
|
||
double const minimum_bal = 500.0; | ||
class InsufficientFunds{}; | ||
|
||
class Account { | ||
private: | ||
double bal_; | ||
long actNum_; | ||
string firstName_; | ||
string lastName_; | ||
static long nextActNum_; | ||
public: | ||
// Constructors | ||
Account() {}; | ||
Account(string firstName, string lastName, double bal); | ||
|
||
// Accesors | ||
double bal(); | ||
long actNum(); | ||
string firstName(); | ||
string lastName(); | ||
|
||
void deposit(double amount); | ||
void withdraw(double amount); | ||
static void lastActNum(long actNum); | ||
static long lastActNum(); | ||
|
||
// Operator overloading | ||
friend ofstream &operator << (ofstream &ofs, Account &acccount); | ||
friend ifstream &operator >> (ifstream &ifs, Account &account); | ||
friend ostream &operator << (ostream &os, Account &account); | ||
}; | ||
|
||
class Bank{ | ||
private: | ||
map<long, Account> accounts; | ||
public: | ||
//Constructors | ||
Bank(); | ||
// Methods | ||
Account openAct(string firstName, string lastName, double bal); | ||
Account balanceEnquiry(long actNum); | ||
Account deposit(long actNum, double amount); | ||
Account withdraw(long actNum, double amount); | ||
void closeAccount(long actNum); | ||
void showAllAccounts(); | ||
~Bank(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "banking.cpp" | ||
|
||
int main(){ | ||
|
||
Bank bank; | ||
Account account; | ||
|
||
int choice; | ||
string fname, lname; | ||
long actNum; | ||
double balance; | ||
double amount; | ||
|
||
cout << "\n\t******** Welcome to Our Banking System ***********" << endl; | ||
do { | ||
cout << "\n\t Select one option below"; | ||
cout << "\n\t 1: Open an Account"; | ||
cout << "\n\t 2: Balance Enquiry"; | ||
cout << "\n\t 3: Deposit Money"; | ||
cout << "\n\t 4: Withdraw Money"; | ||
cout << "\n\t 5: Close an Account"; | ||
cout << "\n\t 6: Show all Accounts"; | ||
cout << "\n\t 7: Quit"; | ||
cout << "\nEnter your choice: "; | ||
cin >> choice; | ||
switch (choice) | ||
{ | ||
case 1: // Open an account | ||
cout << "Enter first name: "; cin >> fname; | ||
cout << "Enter last name: "; cin >> lname; | ||
cout << "Enter initial balance: "; cin >> balance; | ||
account = bank.openAct(fname, lname, balance); | ||
cout << "\nCongratulations! Account opened successfully!\n"; | ||
cout << account; | ||
break; | ||
case 2: // Balance enquiry | ||
cout << "Enter the account number: "; cin >> actNum; | ||
account = bank.balanceEnquiry(actNum); | ||
cout << "Your balance enquiry is: " << account; | ||
break; | ||
case 3: // Deposit money | ||
cout << "Enter the account number: "; cin >> actNum; | ||
cout << "Enter amount to deposit: "; cin >> amount; | ||
account = bank.deposit(actNum, amount); | ||
cout << "The sum of " << amount | ||
<< " has been deposited to the account associated with the account number " << actNum; | ||
break; | ||
case 4: // Withdraw money | ||
cout << "Enter the account number: "; cin >> actNum; | ||
cout << "Enter amount to withdraw: "; cin >> amount; | ||
account = bank.withdraw(actNum, amount); | ||
cout << "The sum of " << amount | ||
<< " has been withdrawn from the account associated with the account number " << actNum; | ||
break; | ||
case 5: // Close an account | ||
cout << "Enter the account number: "; cin >> actNum; | ||
bank.closeAccount(actNum); | ||
cout << "The account having the account number " << actNum << " was closed successfully"; | ||
break; | ||
case 6: // Show all accounts | ||
bank.showAllAccounts(); | ||
break; | ||
case 7: // Quit | ||
break; | ||
default: | ||
cout << "Enter a valid choice"; | ||
exit(0); | ||
} | ||
} while (choice != 7); | ||
|
||
return 0; | ||
} |