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类的个体数目的更多相关文章

  1. LogHelper 日志记录帮助类

    1.LogHelper 日志记录帮助类 using System; using System.Collections.Generic; using System.Linq; using System. ...

  2. 封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil

    封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil,代码比较简单,主要是把MongoTarget的配置.FileTarget的配置集成到类中,同时利用缓存依赖来判断是否需要重新创 ...

  3. 封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil,nloglogutil

    封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil,代码比较简单,主要是把MongoTarget的配置.FileTarget的配置集成到类中,同时利用缓存依赖来判断是否需要重新创 ...

  4. C# 日志记录工具类--LogHelper.cs测试

    C# 日志记录工具类:(适用于不想使用log4j等第三方的Log工具的时候,希望自己写个简单类实现)LogHelper.cs内容如下: using System; using System.Diagn ...

  5. Go/Python/Erlang编程语言对比分析及示例 基于RabbitMQ.Client组件实现RabbitMQ可复用的 ConnectionPool(连接池) 封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil 分享基于MemoryCache(内存缓存)的缓存工具类,C# B/S 、C/S项目均可以使用!

    Go/Python/Erlang编程语言对比分析及示例   本文主要是介绍Go,从语言对比分析的角度切入.之所以选择与Python.Erlang对比,是因为做为高级语言,它们语言特性上有较大的相似性, ...

  6. php之框架增加日志记录功能类

    <?php /* 思路:给定文件,写入读取(fopen ,fwrite……) 如果大于1M 则重写备份 传给一个内容, 判断大小,如果大于1M,备份 小于则写入 */ class Log{ // ...

  7. python记录_day019 类的约束 异常处理 日志

    一 .约束 python中约束有两种 第一种,通过抛异常进行约束,这种是子类不按我要求的来,我就给你抛异常(推荐) 操作:提取一个父类. 在父类中给出一个方法.但在方法中不给出任何代码,直接抛异常 # ...

  8. python记录_day17 类与类之间的关系

    一.依赖关系 a类的对象是b类方法的参数 这种关系是我用着你,但你不属于我,比如公司和临时工的关系,是很弱的一种关系 class Zhiwu: def __init__(self,name,atk): ...

  9. VS2010 MFC中 单独添加ODBC数据库记录集类(CRecordset)方法

    基于VS2010 MFC的项目是之前建好的,后来需要添加数据库. 方法分享于此. 1.  打开自己的项目,项目->添加类. 2. 选MFC ODBC使用者,点右下角的添加. 3. 点数据源. / ...

随机推荐

  1. NOP初学记录

    1.  介绍的话不多说了.直接先来简单的安装跟配置先以3.6版本为例: 附带官网地址: http://www.nopcommerce.com   自行下载. 中文网:http://www.nopchi ...

  2. shell变量的使用

    转载请标明http://www.cnblogs.com/winifred-tang94/ shell环境中变量有三种类型: a.  环境变量:可以在shell脚本中直接利用“$环境变量名称”的形式引用 ...

  3. Python单元测试——unittest

    unittest是python自带的一个模块 python344\Lib\unittest 官方参考文档: http://docs.python.org/2.7/library/unittest.ht ...

  4. <矩阵的基本操作:矩阵相加,矩阵相乘,矩阵转置>

    //矩阵的基本操作:矩阵相加,矩阵相乘,矩阵转置 #include<stdio.h> #include<stdlib.h> #define M 2 #define N 3 #d ...

  5. 配置VS2010具有代码提示功能

    Visual Assist X是一款非常好的Microsoft Visual Studio插件,可以支持Microsoft Visual Studio 2003,Microsoft Visual St ...

  6. HDOJ-三部曲-1015-The Cow Lexicon

    The Cow Lexicon Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

  7. Hello Qt

    版本:Qt 5.5.1 Windows 参考: C++ GUI Programming with Qt 4 Second Edition 1. 打开 Qt Creator,File -> New ...

  8. Minimum Inversion Number_线段树||树状数组

    Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of ...

  9. Digit (数位DP)

    一个正整数的价值就是把这个数的十进制写出来之后,最长的等差子串的长度. 求出在[l,r]范围内的数字的价值总和. (l<=r<=10^12) 记f[now,ml,l,d,pre,st,li ...

  10. 打开office弹出steup error 的解决办法

    找到 C:\Program Files\Common Files\Microsoft Shared\OFFICE12\Office Setup Controller 将这个文件夹删除