zoukankan      html  css  js  c++  java
  • sdut 3-6 静态数据成员与静态成员函数

    3-6 静态数据成员与静态成员函数

    Time Limit: 1000MS Memory limit: 65536K

    题目描写叙述

    通过本题目的练习能够掌握静态数据成员和静态成员函数的使用方法

    要求设计一个点类Point,它具有两个double型的数据成员xy。和一个静态数据成员count ,用以记录系统中创建点对象的数目。为该类设计构造函数和析构函数,在当中对count的值做改动。体现点的数目的动态变化。

    并为其加入一个静态成员函数用以输出count的值;成员函数showPoint()用于输出点的信息。

    并编写主函数,输出下面的内容。

    输入

     

    输出

     

    演示样例输入

    演示样例输出

    x=0,Y=0
    the number of points is 3
    Deconstructor point x=5
    Deconstructor point x=3
    Deconstructor point x=0

    提示

     

    来源

     黄晶晶

    演示样例程序

    #include <iostream>
    
    using namespace std;
    
    class point
    {
    private :
        double x, y;
        static int count;//静态数据成员
    
    public:
        static void showpoint();//声明静态成员函数
        void display()
        {
            cout<<"Deconstructor point x=" << x << endl;
        }
    
        point(double a=0, double b=0)
        {
            count++;
            x=a;
            y=b;
        }
    };
    
    int point::count = 0;
    
    //定义静态成员函数
    void point::showpoint()
    {
        cout << "x=0,Y=0" << endl;
        cout << "the number of points is " << count << endl;
    }
    int main()
    {
        point a(5), b(3), c(0);
        point::showpoint();
        a.display();
        b.display();
        c.display();
        return 0;
    }
    


  • 相关阅读:
    python课堂整理5---元组
    用python输出回文数
    python课堂整理4---列表的魔法
    python基础知识练习题一
    python课堂整理3---字符串魔法
    python课堂整理2
    python课堂整理1
    励志程序媛---从厂妹到Google年薪60W RMB程序员
    动态链接库--靠谱
    基于VS2019———C++生成自己的静态链接库————良心实战笔记
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/6759021.html
Copyright © 2011-2022 走看看