zoukankan      html  css  js  c++  java
  • 记录Cat类的个体数目

    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);
        }
    }

  • 相关阅读:
    Mayan游戏
    选择客栈
    Redundant Paths
    中心选址
    辗转相除
    字符串
    线段覆盖
    配置魔药
    宝库通道
    教官的监视
  • 原文地址:https://www.cnblogs.com/zeross/p/4523065.html
Copyright © 2011-2022 走看看