3. (C) Design a class StaticDemo to show the implementation of static variable and static function.
| ||
| 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.
Reviewed by admin
on
December 23, 2019
Rating:
Reviewed by admin
on
December 23, 2019
Rating:

No comments: