3. (C) Design a class StaticDemo to show the implementation of static variable and static function.

3. (C) Design a class StaticDemo to show the implementation of static variable and static function.
Design a class StaticDemo to show the implementation of static variable and static function.


#include<iostream.h> #include<conio.h>
class test
{
int code;
static int count;
public:
void setcode()
{
code=++count;
}
void showcode(void)
{
cout<<"object number="<<code<<"\n";
}
static void showcount(void)
{
cout<<"count."<<count<<"\n";
}
};
int test::count;
void main()
{
clrscr();
test t1,t2;
t1.setcode();
t2.setcode();
test::showcount();
test t3;t3.setcode();
test::showcount();
t1.showcode();
t2.showcode();
t3.showcode();
getch();
}
3. (C) Design a class StaticDemo to show the implementation of static variable and static function. 3. (C) Design a class StaticDemo to show the implementation of static variable and static function. Reviewed by admin on December 23, 2019 Rating: 5

No comments:

Powered by Blogger.