Monday, 8 June 2015

Program to illustrate static member functions



Code for Program to illustrate static member functions in C++ Programming



 



 



#include<iostream.h>
 #include<conio.h>

 /*************************************************************************///------------------------------  check  --------------------------------///*************************************************************************/class check
    {
       private:
        int data1;
        staticint data2;

       public:
        void setvalue(int);
        void showdata();
        staticvoid showcount();
    };

 /*************************************************************************///---------------------  static data initialization  --------------------///*************************************************************************/int check::data2=0;

 /*************************************************************************///---------------------------  setvalue(int)  ---------------------------///*************************************************************************/void check::setvalue(intvalue)
    {
       data1=value;
       data2=value;
    }

 /*************************************************************************///---------------------------  showdata( )  -----------------------------///*************************************************************************/void check::showdata()
    {
       cout<<"\n\t ordinary data = data1 = "<<data1<<endl;
       cout<<"\t static data = data2 = "<<data2<<endl;
    }

 /*************************************************************************///---------------------------  showcount( )  ----------------------------///*************************************************************************/void check::showcount()
    {
       cout<<"\n\t static with static is "<<data2<<endl;
    }

 main( )
    {
       clrscr();

       check obj1;
       check obj2;

       obj1.setvalue(5);
       obj1.showdata();

       obj2.showdata();

       check::showcount();

       getch();
       return 0;
} 
 

No comments:

Post a Comment