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>
using namespace std;
class Bank {
private:
int cid;
char cname[15];
float balance;
public:
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.
/* This function receive two Bank objects as arguments
* and perform 1000 balance transfer from object a1 balance to object a2 balance.*/
friend void balanceTransfer(Bank& a1, Bank& a2);
};
void Bank::read()
{
cout << "ID : ";
cin >> cid;
cout << "Name : ";
cin >> cname;
cout << "Balance : ";
cin >> balance;
}
void Bank::print()
{
cout << cid << " " << cname << " - " << balance << endl;
}
void balanceTransfer(Bank& a1, Bank& a2)
{
a1.balance -= 1000;
a2.balance += 1000;
}
int main()
{
Bank a1;
Bank a2;
cout << "Enter the details of the first user." << endl;
a1.read();
cout << "\nEnter the details of the second user." << endl;
a2.read();
cout << "\nUsers info:" << endl;
a1.print();
a2.print();
cout << "\nThe first user transfers $1,000 to the second user..." << endl << endl;
balanceTransfer(a1, a2);
cout << "\nUsers info:" << endl;
a1.print();
a2.print();
}
Comments
Leave a comment