Three private variables: int cid,char cname[15] & float balance
Three public member functions:
void read() - This function should read the value of cid, cname & balance from user.
void print() - This method should display the value of cid, cname & balance.
void balanceTransfer(Bank &a1,Bank &a2) - This function receive two Bank objects as arguments and perform 1000 balance transfer from object a1 balance to object a2 balance.
#include <iostream>
#include<iomanip>
using namespace std;
class Account
{
int id;
char name;
float balance;
public:
Account()
{
name = "";
id=0;
balance = 0;
};
Account(char name, float balance)
{
name = cname;
id=cid;
balance = balance;
};
void read()
{
cout<<"Enter name : ";
getline (cin, cname);
cout<<"Enter id number : ";
cin>>id;
cout<<"Enter balance : ";
cin>>balance;
};
void print()
{
cout<<setw(20)<<cname<<setw(15)<<cid<<setw(15)<<balance
<<endl;
};
Account transferBalance(Account A2, float tbalance)
{
if (balance > tbalance)
{
balance -= tbalance;
A2.balance += tbalance;
}
else
{
cout<<endl
<<"Sorry! Transfer failed! Reason: Insufficient Balance."
<<endl;
}
return A2;
};
};
int main()
{
Account A1, A2;
float tbalance;
cout<<"Enter Details of transfering Account(Account 1)\n";
A1.read();
cout<<endl
<<"Enter Details of receiving Account(Account 2)\n";
cin.ignore(); read();
cout<<endl
<<"Enter total amount which you want to transfer from Account 1 to Account 2: ";
cin>>tbalance;
A2 = A1.transferBalance(A2, tbalance);
cout<<endl;
cout<<setw(29)<<"Name"<<setw(15)<<"ID"<<setw(15)<<"Balance"<<endl;
cout<<"Account 1";A1.print();
cout<<"Account 2";A2.print();
return 0;
}
Comments
Leave a comment