Answer to Question #178338 in C++ for Shavani

Question #178338

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.


1
Expert's answer
2021-04-05T04:22:27-0400
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS