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

  • 相关阅读:
    设计模式
    Junit单元测试
    数组存储和链表存储
    java新特型
    List&&Set
    Map
    File文件
    1588. 所有奇数长度子数组的和
    2秒后跳转到某页面
    图片轮播/倒计时--windows对象(setInterval)
  • 原文地址:https://www.cnblogs.com/zeross/p/4523065.html
Copyright © 2011-2022 走看看