C++ program to illustrate the static member function

Saturday, March 13th, 2010

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

Avatar Image

Author Name :
Ranjith

Total : 3 Comments


3 Responses to C++ program to illustrate the static member function

  1. bishnu

    i need a program that illustrate the call by value and reference
    of object of a class. send it to my email id.
    bishnu_nayak2009@yahoo.in

  2. mymoonasiya

    hi thanx.i want one example program in static member functions and static data members plz sent it tomorrow plz i need it fast send to mail mail.ID:mymoonasiya@yahoo.com

  3. soha sheikh

    plz mujhe friend class and friend fucton ka program with description chaiye,means how the procedure in a prog work.plz give overall explaination step by step.nd send me in farheenn44@gmail.com.thax a lot.

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup