-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6702 from Umeshch2004/main
Create CPP
- Loading branch information
Showing
1 changed file
with
199 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,199 @@ | ||
|
||
#include<iostream> | ||
#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) | ||
{ | ||
firstname=fname; | ||
lastname=lname; | ||
balance=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 balanceenqiry(long accountnumber); | ||
account deposit(long accountnumber,float amount); | ||
account withdraw(long accountnumber,float amount); | ||
void closeaccount(long accountnumber); | ||
void showallaccount(); | ||
~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\t 1 open an account "; | ||
cout<<"\n\t 2 Balance Enquiry "; | ||
cout<<"\n\t 3 Deposit"; | ||
cout<<"\n\t 4 withdrawl"; | ||
cout<<"\n\t 5 close an account"; | ||
cout<<"\n\t 6 show all account"; | ||
cout<<"\n\t 7 quit"; | ||
cout<<"\n Enter your choice"; | ||
cin>>choice; | ||
switch(choice) | ||
{ | ||
case 1: | ||
cout<<"Enter first name: "; | ||
cin>>fname; | ||
cout<<"Enter last name :"; | ||
cin>>lname; | ||
cout<<"Enter intial balance: "; | ||
cin>>balance; | ||
acc=b.openaccount(fname,lname,balance); | ||
cout<<endl<<"Congratulations account is created"; | ||
cout<<acc; | ||
break; | ||
case 2: | ||
cout<<"Enter account number: "; | ||
cin>>accountnumber; | ||
acc=b.balanceenqiry(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; | ||
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 closed"<<endl; | ||
cout<<acc; | ||
break; | ||
case 6: | ||
b.showallaccount(); | ||
break; | ||
case 7: | ||
break; | ||
default: | ||
cout<<"\nEnter correct 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; | ||
|
||
} | ||
|
||
|
||
|