Skip to content

Instantly share code, notes, and snippets.

@poudelmadhav
Last active July 18, 2025 12:52
Show Gist options
  • Select an option

  • Save poudelmadhav/6b7264c97c377f094b3cb765d05589a3 to your computer and use it in GitHub Desktop.

Select an option

Save poudelmadhav/6b7264c97c377f094b3cb765d05589a3 to your computer and use it in GitHub Desktop.
C++ program to transfer money from one account to another
/******************************************************************************
Balance Transfer
//Author Madhav Paudel
*******************************************************************************/
#include <iostream>
#include<iomanip>
using namespace std;
class Account
{
string name;
long int accno;
long int balance;
public:
Account()
{
name = "";
accno = 0;
balance = 0;
};
Account(string name, long int accno,long int balance)
{
name = name;
accno = accno;
balance = balance;
};
void setData()
{
cout<<"Enter name : ";
getline (cin, name);
cout<<"Enter account number : ";
cin>>accno;
cout<<"Enter balance : ";
cin>>balance;
};
void display()
{
cout<<setw(20)<<name<<setw(15)<<accno<<setw(15)<<balance
<<endl;
};
Account transferBalance(Account A2, long int 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;
long int tbalance;
cout<<"Enter Details of transfering Account(Account 1)\n";
A1.setData();
cout<<endl
<<"Enter Details of receiving Account(Account 2)\n";
cin.ignore(); A2.setData();
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)<<"Accno"<<setw(15)<<"Balance"<<endl;
cout<<"Account 1";A1.display();
cout<<"Account 2";A2.display();
return 0;
}
@poudelmadhav
Copy link
Copy Markdown
Author

is this call by reference method?

No, it is not called by the reference method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment