Friday, September 26, 2014

WAP to transfer the given amount of money from one account to another by using the concept of passing objects by pointers. For this create a class with suitable data members and necessary member functions.

#include
#include
class account
{
            private:
   int accno;
   float balance;
   public:
   void getdata()
   {
            cout<<"Enter account no.:";
      cin>>accno;
      cout<<"Enter balance:";
      cin>>balance;
   }
   void display()
   {
            cout<<"Account number is"<
      cout<<"Balance is"<
   }
   void moneytransfer(account *acc,float amt);
};
void account::moneytransfer(account *acc,float amt)
{
            balance=balance-amt;
   acc->balance=acc->balance+amt;
}
main()
{
            float money;
   account acc1,acc2;
   acc1.getdata();
   acc2.getdata();
   cout<<"A/C info:"<
   acc1.display();
   acc2.display();
   cout<<"How much money to be transferred from account 2 to account 1"<
   cin>>money;
   acc2.moneytransfer(&acc1,money);
   cout<<"Updated info of account:"<
   acc1.display();
   acc2.display();
   getch();

}

No comments:

Post a Comment