1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include <iostream>
#include <string>
using namespace std;
class account{
private:
string Dname, AccountType, AccountNum;
float balance;
public:
void setdata(string, string, string);
void setbalance(float);
void deposit(float);
void withdraw(float);
void initializer(void);
void displaydata(void);
float getbalance(void);
string getaccnum(void);
friend void tranfer(account,string,float);
};
void account::setdata(string a, string b, string c){
Dname = a;
if(b != ""){
AccountType = b;
}
AccountNum = c;
}
void account::deposit(float x){
balance = balance + x;
}
void account::withdraw(float z){
if(z >= balance){
cout<<"Insufficient Funds.\n";
}
else{
balance = balance - z;
}
}
void account::initializer(void){
balance = 300000.00;
AccountType = "Savings";
}
void account::displaydata(void){
cout<< "Account Holder: " << Dname << endl;
cout<< "Account Type: " << AccountType << endl;
cout<< "Account Numebr: " << AccountNum << endl;
cout<< "Account Balance: " << balance << endl;
}
float account::getbalance(void){
return balance;
}
string account::getaccnum(void){
return AccountNum;
}
void account::setbalance(float y){
balance = y;
}
void tranfer(account object, string temp2, float amount){
{
float tempo;
if(object.getbalance() <= amount){
cout << "Sorry Transaction not possible,Insufficient Funds";
}
else{tempo = object.getbalance();
tempo = tempo - amount;
object.setbalance(tempo);
}
}
{
float tempo2;
account object2[2];
for(int j = 0; j <= 1; ++j){
if(object2[j].getaccnum() == temp2){
tempo2 = object2[j].getbalance();
tempo2 = tempo2 + amount;
object2[j].setbalance(tempo2);
cout << "New Balance for Account " << temp2;
}
}
cout << "New Balance for Account " << object.getaccnum() << " is: " << object.getbalance();
}
int main (){
account object[2];
string a,b,c,temp,temp2;
float x,z,amount;
int choice,endelea;
for(int i = 0; i<=1; ++i)
{
object[i].initializer();
cout << "Please Enter Depositor's name: ";
getline(cin,a);
cout << "Please Enter Account Type: ";
getline(cin,b);
cout << "Please Enter Account Number: ";
getline(cin,c);
object[i].setdata(a,b,c);
cout << endl;
}
for(int i = 0; i <=1; ++i){
object[i].displaydata();
cout << "******************************************************\n";
}
cout << "Please choose Account by Entering Account Number: ";
getline(cin,temp);
cout << "Enter Number to select Transaction \n" << "1: Check Balance \n" << "2: Withdraw \n" << "3: Deposit\n" << "4: Transfer\n";
cin >> choice;
for(int i=0; i<=1; ++i){
if(choice == 1 && object[i].getaccnum() == temp){
cout << "Your Balance is: " << object[i].getbalance();
}
else if(choice == 2 && object[i].getaccnum() == temp){
cout << "Please Enter amount to withdraw: ";
cin >> z;
object[i].withdraw(z);
object[i].displaydata();
}
else if(choice == 3 && object[i].getaccnum() == temp){
cout << "Please Enter Amount to Deposit: ";
cin >> x;
object[i].deposit(x);
object[i].displaydata();
}
else if(choice == 4 && object[i].getaccnum() == temp){
cout << "Please Enter Account Number of Account to Transfer to: ";
cin >> temp2;
cout << "Please Enter Amount to Transfer: ";
cin >> amount;
tranfer(object[i], temp2, amount);
}
}
return 0;
}.
|