stu nicholls dot com | menu - Professional dropdown #3

//Sample Program to demonstrate the use of static variable, default & parameterized constructor and destructor 
#include < iostream.h >
#include < conio.h >
class item{
     static int count;
     int number;
     public:
     item(){number=0;}
     void getdata (int a)
	  {
	  number = a;
	  count ++;
	  }
     void getcount ()
	  {
	  cout << "\n number: " << number << endl;
	  cout << "\n count: ";
	  cout << count << endl;
	  }
	  ~item(){cout << "\n Destroying the object\n";}
     };
     int item ::count;
     void main()
	{
	item a,b,c;
	clrscr();
	cout << "\n Objects created calling default construcutor\n";
	a.getcount();
	b.getcount();
	c.getcount();
	cout << "\n Objects created with parameterized construcutor\n" << "\n";
	a.getdata(100);
	b.getdata(200);
	c.getdata(300);
	a.getcount();
	b.getcount();
	c.getcount();
	getch();
	}
GO BACK
Footer1