码迷,mamicode.com
首页 > 其他好文 > 详细

记录Cat类的个体数目

时间:2015-05-22 20:51:24      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

B.记录Cat类的个体数目
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 22 (17 users) Total Accepted: 12 (12 users) Special Judge: No
Description

定义一个Cat类,拥有静态数据成员HowManyCats,记录Cat的个体数目;静态成员函数GetHowMany(),存取HowManyCats。设计程序测试这个类。

Input

输入整数n,n代表最大的Cat数量。

Output
分行显示HowManyCats值的变化过程。从1..n及从n-1..0的过程。
Sample Input

5

Sample Output

 

There are 1 cats alive!

  There are 2 cats alive!

  There are 3 cats alive!

  There are 4 cats alive!

  There are 5 cats alive!

  There are 4 cats alive!

  There are 3 cats alive!

  There are 2 cats alive!

  There are 1 cats alive!

  There are 0 cats alive!

#include<iostream>
using namespace std;
class cat
{
    public: void getHowMany(int a);
    static int HowManyCats;
};
void cat::getHowMany(int a)
{
    cout<<"There are "<<a<<" cats alive!"<<endl;
}
int cat::HowManyCats=0;
int main()
{
    cat cat1;
    int n;
    cin>>n;
    while(cat1.HowManyCats<n)
    {
        cat1.HowManyCats++;
        cat1.getHowMany(cat1.HowManyCats);
    }
    while(cat1.HowManyCats>0)
    {
        cat1.HowManyCats--;
        cat1.getHowMany(cat1.HowManyCats);
    }
}

记录Cat类的个体数目

标签:

原文地址:http://www.cnblogs.com/zeross/p/4523065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!