C++ program to illustrate the static member function

AIM
Write a program to illustrate the static member function.

ALGORITHM

1. Start the process
2. Invoke the class
i. Set the data member and member function as a static
b. Create two objects t1 and t2
3. Call the function t1.setcode
i. Increment the value of data member count
4. Call the function t1.setcode
i. Increment the value of data member count
5. Call the static member function showcount()
i. Display the value of count
6. Create a new object t3
7. Call the function t3.set code()
8. Call t1.showcount(), t2.showcount() and t3.showcount()
9. Stop the process

PROGRAM

#include<iostream.h>
#include<conio.h>
 
class test
{
	int code;
	static int count;
	public :
		void setcode(void)
		{
			code= ++count;
		}
		void showcode(void)
		{
			cout<<"object number"<<code<<endl;
		}
		static void showcount(void)
		{
			cout<<"count"<<count<<endl;
		}
};
int test::count;
 
int main()
{
	clrscr();
	test t1,t2;
	t1.setcode();
	t2.setcode();
	test::showcount();
	test t3;
	t3.setcode();
test::showcount();
	t1.showcode();
	t2.showcode();
	t3.showcode();
	getch();
	return(1);	    
}

OUTPUT

Count 2
Count 3
Object number 1
Object number 2
Object number 3

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

16 thoughts on “C++ program to illustrate the static member function

  1. i like your program but i want some thing different beacuse i saw this program in many books so i want different program to under stand the logic more clear.

  2. i cant understand your program i want more easily&simply&easliymugup.
    i need fully explantion of the program. please help .
    i did not basic on c++program.

  3. i want somewhat simple program as i am learning this know and cant understand complex programs

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in