C++第5次作业.docVIP

  • 10
  • 0
  • 约5.24千字
  • 约 11页
  • 2017-03-23 发布于重庆
  • 举报
C第5次作业

实验五:数据的共享与保护 1. 定义一个Cat类,拥有静态数据成员HowManyCats,记录Cat的个体数目;静态成员函数GetHowMany(),存取HowManyCats。设计程序测试这个类,体会静态数据成员和静态成员函数的用法。 (1) 实验分析:本题的难点就是(2) 程序代码:#include iostream #include string using namespace std; class Cat { public: Cat(string name=Untitle,double age=0,double weight=0):name(name),age(age),weight(weight){HowManyCats++;} Cat(Cat c):name(c.name),age(c.age),weight(c.weight){} static int GetHowMany(); void showCat(); private: string name; double age,weight; static int HowManyCats; }; int Cat::HowManyCats=0; int Cat::GetHowMany() { return HowManyCats; } void Cat::showCat() { for(

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档