IMPLEMENTATION OF STATIC MEMBERS - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Tuesday, October 26, 2010

IMPLEMENTATION OF STATIC MEMBERS


Program:

#include<iostream.h>
#include<conio.h>
class staticmember
{
 int a;
 static int count,cnt;
 public:
       void set()
       {
        a=++count;
        cnt++;
       }
       void show()
       {
            cout<<"\n";
            cout<<"Object Number:"<<a<<"\n";
       }
       static void showcount()
       {
         cout<<"Static count value:"<<count<<"\n";
         cout<<"Static cnt value:"<<cnt<<"\n";
       }
};
int staticmember::count;
int staticmember::cnt = 100;
void main()
{
  staticmember s1,s2,s3;
  clrscr();
  s1.set();
  s1.show();
  cout<<endl;
  s2.set();
  staticmember::showcount();
  s2.show();
  cout<<endl;
  s3.set();
  staticmember::showcount();
  s3.show();
  cout<<endl;
  getch();
}

No comments:

Post a Comment