Program for the use of constructor and function..
#include<iostream.h>
#include<conio.h>
class incm
{
public:
int i;
incm()
{
i=0;
}
void add()
{
i++;
}
void sub()
{
i--;
}
void show()
{
cout<<"\n\t"<<i<<endl;
}
};
void main()
{
clrscr();
incm c1,c2;
c1.add();
c1.add();
c2.sub();
c2.sub();
c1.sub();
c2.add();
c1.show();
c2.show();
getch();
}
Here is the output :)
No comments:
Post a Comment