Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program that provides an example of class, object and constructors

Posted By: Imogen Brown     Category: C++ Programming     Views: 4049

Write a program that provides an example of class, object and constructors.

Code for Program that provides an example of class, object and constructors in C++ Programming

#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;
}
  
Share: 



Imogen Brown
Imogen Brown author of Program that provides an example of class, object and constructors is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!