AIM:

          To write a C++ program using static data member and static member function.

ALGORITHM:

STEP 1: Start the program.

STEP 2: Declare static variable ‘count’.

STEP 3: Define static variable ‘count’ outside of the class.

STEP 4: Define member function ‘show count()’ for displaying the value of count.

STEP 5: Call the static function in main function.

STEP 6: Stop the program.

PROGRAM CODE:

#include<iostream.h>
#include<conio.h>
class test
{ int code; static int count; public: void setcode() { code=++count; } void showcode() { cout<<"n Code = "<<code<<"n"; } static void showcount() { cout<<"n Count = "<<count; }
};
int test::count=0;
void main()
{ clrscr(); test t1; t1.setcode(); t1.showcode(); t1.showcount(); getch();
}
OUTPUT:

static

RESULT:

                 Thus the C++ program using static data member and static member function is written and executed successfully.

Similar Posts