Saturday, 16 May 2015

U4P2

Write a program that demonstrates the Static Data Member And static member function.

Code :
 #include<iostream.h>  
 #include<conio.h>  
 class test  
 {  
      int code;  
      static int count;  
      public:  
      void setcode()  
      {  
           code=++count;  
      }  
      void showcode()  
      {  
           cout<<"\nObject Num : "<<code;  
      }  
      static void showcount()  
      {  
           cout<<"\nCount : "<<count;  
      }  
 };  
 int test::count;  
 void main()  
 {  
      clrscr();  
      test t1,t2;  
      t1.setcode();  
      t2.setcode();  
      test::showcount();  
      test t3;  
      t3.setcode();  
      test::showcount();  
      t1.showcode();  
      t2.showcode();  
      t3.showcode();  
      getch();  
 }  

Output : 

No comments:

Post a Comment