Saturday, September 27, 2014

Create a class with a data member to hold serial number for each object created from the class i.e. the first object created will be numbered 1 the second 2 and so on by using the basic concept of static data members. Use static member function if it is useful in any of the member functions declared in the program. Otherwise make separate program that demonstrates the use of static member function.

#include
#include
class staticdata
{
     private:
                static int c;
     public:
                staticdata()
                {
                                c++;
                }
                int getc()
                {
                                return c;
                }
};
int staticdata::c=0;
main()
{
                clrscr();
                staticdata s1,s2,s3;
                cout<<"count is"<
                cout<<"count is"<
                cout<<"count is"<
                getch();


}

No comments:

Post a Comment