Tuesday, 7 April 2020

Program : Write a Program to design a class having static member function named showcount() which has the property of displaying the number of objects created of the class.

#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<<"\n";

static void showcount(void) 

cout<<"count:"<<count<<"\n"; 
}
};

int test :: count;
int main()

test t1,t2;
t1.setcode(); 
t2.setcode();
test :: showcount();
test t3;
t3.setcode();
test :: showcount(); 
t1.showcode(); 
t2.showcode(); 
t3.showcode(); 
return 0;
}

No comments:

Post a Comment