C++ Programming Blog

 
 
 
#include<iostream.h>
#include<conio.h>
class account
{
    int bal;
    float rate;
    public:
        account(int bal,float rate);
        void deposit(int amt);
        void withdraw(int amt);
        void disp_bal();
};

main()
{
    clrscr();
    account a1=account(1000,10);
    account a2(1500,20);
    a1.deposit(300);
    a1.withdraw(20);
    a1.disp_bal();
    a2.deposit(200);
    a2.withdraw(50);
    a2.disp_bal();
}

account::account(int b1,float rt)
{
    bal=b1;
    rate=rt;
}
void account::deposit(int amt)
{
    bal=bal+amt;
}
void account::withdraw(int amt)
{
    bal=bal-amt;
}
void account::disp_bal()
{
    cout<<\"Balance is : \"<<bal<<endl;
}

 
 
Didn't find what you were looking for? Find more on Program that provides an example of class, object and constructors