Saturday, 23 June 2012

write a c++ program to design a class which contain static data member and member function show() which display number of times display operation is performed irrespective of the object responsible for display using static data member

/* write a c++ program to design a class which contain static data member and member function
show() which display number of times display operation is performed
irrespective of the object responsible for display using static data
member*/
#include<conio.h>
#include<iostream.h>
class number
{
public:static int cnt;
public:static void show()
       {
       cnt++;
       cout<<"\nnumber of times display operation is performed:-"<<cnt;
       }
};
int number::cnt;
int main()
{
number n1,n2,n3,n4;
clrscr();
n1.show();
n2.show();
n3.show();
n4.show();
getch();
return 0;
}
/*

number of times display operation is performed:-1
number of times display operation is performed:-2
number of times display operation is performed:-3
number of times display operation is performed:-4
*/

No comments: