-
Notifications
You must be signed in to change notification settings - Fork 24
Banking system project for beginners #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ankitverma3507
wants to merge
1
commit into
VickyTheRocker:main
Choose a base branch
from
Ankitverma3507:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,258 @@ | ||
| Banking System | ||
| #include<iostream> | ||
| #include<fstream> | ||
| #include<cstdlib> | ||
| #include<vector> | ||
| #include<map> | ||
| using namespace std; | ||
| #define MIN_BALANCE 500 | ||
| class InsufficientFunds{}; | ||
| class Account | ||
| { | ||
| private: | ||
| long accountNumber; | ||
| string firstName; | ||
| string lastName; | ||
| float balance; | ||
| static long NextAccountNumber; | ||
| public: | ||
| Account(){} | ||
| Account(string fname,string lname,float balance); | ||
| long getAccNo(){return accountNumber;} | ||
| string getFirstName(){return firstName;} | ||
| string getLastName(){return lastName;} | ||
| float getBalance(){return balance;} | ||
|
|
||
| void Deposit(float amount); | ||
| void Withdraw(float amount); | ||
| static void setLastAccountNumber(long accountNumber); | ||
| static long getLastAccountNumber(); | ||
| friend ofstream & operator<<(ofstream &ofs,Account &acc); | ||
| friend ifstream & operator>>(ifstream &ifs,Account &acc); | ||
| friend ostream & operator<<(ostream &os,Account &acc); | ||
| }; | ||
| long Account::NextAccountNumber=0; | ||
| class Bank | ||
| { | ||
| private: | ||
| map<long,Account> accounts; | ||
| public: | ||
| Bank(); | ||
| Account OpenAccount(string fname,string lname,float balance); | ||
| Account BalanceEnquiry(long accountNumber); | ||
| Account Deposit(long accountNumber,float amount); | ||
| Account Withdraw(long accountNumber,float amount); | ||
| void CloseAccount(long accountNumber); | ||
| void ShowAllAccounts(); | ||
| ~Bank(); | ||
| }; | ||
| int main() | ||
| { | ||
| Bank b; | ||
| Account acc; | ||
|
|
||
| int choice; | ||
| string fname,lname; | ||
| long accountNumber; | ||
| float balance; | ||
| float amount; | ||
| cout<<"***Banking System***"<<endl; | ||
| do | ||
| { | ||
| cout<<"\n\tSelect one option below "; | ||
| cout<<"\n\t1 Open an Account"; | ||
| cout<<"\n\t2 Balance Enquiry"; | ||
| cout<<"\n\t3 Deposit"; | ||
| cout<<"\n\t4 Withdrawal"; | ||
| cout<<"\n\t5 Close an Account"; | ||
| cout<<"\n\t6 Show All Accounts"; | ||
| cout<<"\n\t7 Quit"; | ||
| cout<<"\nEnter your choice: "; | ||
| cin>>choice; | ||
| switch(choice) | ||
| { | ||
| case 1: | ||
| cout<<"Enter First Name: "; | ||
| cin>>fname; | ||
| cout<<"Enter Last Name: "; | ||
| cin>>lname; | ||
| cout<<"Enter initil Balance: "; | ||
| cin>>balance; | ||
| acc=b.OpenAccount(fname,lname,balance); | ||
| cout<<endl<<"Congradulation Account is Created"<<endl; | ||
| cout<<acc; | ||
| break; | ||
| case 2: | ||
| cout<<"Enter Account Number:"; | ||
| cin>>accountNumber; | ||
| acc=b.BalanceEnquiry(accountNumber); | ||
| cout<<endl<<"Your Account Details"<<endl; | ||
| cout<<acc; | ||
| break; | ||
| case 3: | ||
| cout<<"Enter Account Number:"; | ||
| cin>>accountNumber; | ||
| cout<<"Enter Balance:"; | ||
| cin>>amount; | ||
| acc=b.Deposit(accountNumber, amount); | ||
| cout<<endl<<"Amount is Deposited"<<endl; | ||
| cout<<acc; | ||
| break; | ||
| case 4: | ||
| cout<<"Enter Account Number:"; | ||
| cin>>accountNumber; | ||
| cout<<"Enter Balance:"; | ||
| cin>>amount; | ||
| acc=b.Withdraw(accountNumber, amount); | ||
| cout<<endl<<"Amount Withdrawn"<<endl; | ||
| cout<<acc; | ||
| break; | ||
| case 5: | ||
| cout<<"Enter Account Number:"; | ||
| cin>>accountNumber; | ||
| b.CloseAccount(accountNumber); | ||
| cout<<endl<<"Account is Closed"<<endl; | ||
| cout<<acc; | ||
| case 6: | ||
| b.ShowAllAccounts(); | ||
| break; | ||
| case 7: break; | ||
| default: | ||
| cout<<"\nEnter corret choice"; | ||
| exit(0); | ||
| } | ||
| }while(choice!=7); | ||
|
|
||
| return 0; | ||
| } | ||
| Account::Account(string fname,string lname,float balance) | ||
| { | ||
| NextAccountNumber++; | ||
| accountNumber=NextAccountNumber; | ||
| firstName=fname; | ||
| lastName=lname; | ||
| this->balance=balance; | ||
| } | ||
| void Account::Deposit(float amount) | ||
| { | ||
| balance+=amount; | ||
| } | ||
| void Account::Withdraw(float amount) | ||
| { | ||
| if(balance-amount<MIN_BALANCE) | ||
| throw InsufficientFunds(); | ||
| balance-=amount; | ||
| } | ||
| void Account::setLastAccountNumber(long accountNumber) | ||
| { | ||
| NextAccountNumber=accountNumber; | ||
| } | ||
| long Account::getLastAccountNumber() | ||
| { | ||
| return NextAccountNumber; | ||
| } | ||
| ofstream & operator<<(ofstream &ofs,Account &acc) | ||
| { | ||
| ofs<<acc.accountNumber<<endl; | ||
| ofs<<acc.firstName<<endl; | ||
| ofs<<acc.lastName<<endl; | ||
| ofs<<acc.balance<<endl; | ||
| return ofs; | ||
| } | ||
| ifstream & operator>>(ifstream &ifs,Account &acc) | ||
| { | ||
| ifs>>acc.accountNumber; | ||
| ifs>>acc.firstName; | ||
| ifs>>acc.lastName; | ||
| ifs>>acc.balance; | ||
| return ifs; | ||
|
|
||
| } | ||
| ostream & operator<<(ostream &os,Account &acc) | ||
| { | ||
| os<<"First Name:"<<acc.getFirstName()<<endl; | ||
| os<<"Last Name:"<<acc.getLastName()<<endl; | ||
| os<<"Account Number:"<<acc.getAccNo()<<endl; | ||
| os<<"Balance:"<<acc.getBalance()<<endl; | ||
| return os; | ||
| } | ||
| Bank::Bank() | ||
| { | ||
|
|
||
| Account account; | ||
| ifstream infile; | ||
| infile.open("Bank.data"); | ||
| if(!infile) | ||
| { | ||
| //cout<<"Error in Opening! File Not Found!!"<<endl; | ||
| return; | ||
| } | ||
| while(!infile.eof()) | ||
| { | ||
| infile>>account; | ||
| accounts.insert(pair<long,Account>(account.getAccNo(),account)); | ||
| } | ||
| Account::setLastAccountNumber(account.getAccNo()); | ||
|
|
||
| infile.close(); | ||
|
|
||
| } | ||
| Account Bank::OpenAccount(string fname,string lname,float balance) | ||
| { | ||
| ofstream outfile; | ||
| Account account(fname,lname,balance); | ||
| accounts.insert(pair<long,Account>(account.getAccNo(),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 accountNumber) | ||
| { | ||
| map<long,Account>::iterator itr=accounts.find(accountNumber); | ||
| return itr->second; | ||
| } | ||
| Account Bank::Deposit(long accountNumber,float amount) | ||
| { | ||
| map<long,Account>::iterator itr=accounts.find(accountNumber); | ||
| itr->second.Deposit(amount); | ||
| return itr->second; | ||
| } | ||
| Account Bank::Withdraw(long accountNumber,float amount) | ||
| { | ||
| map<long,Account>::iterator itr=accounts.find(accountNumber); | ||
| itr->second.Withdraw(amount); | ||
| return itr->second; | ||
| } | ||
| void Bank::CloseAccount(long accountNumber) | ||
| { | ||
| map<long,Account>::iterator itr=accounts.find(accountNumber); | ||
| cout<<"Account Deleted"<<itr->second; | ||
| accounts.erase(accountNumber); | ||
| } | ||
| 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(); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about if you use
Cout << "Full name: ";
getline(cin, fullname);
Instead of using directly cin function