zoukankan      html  css  js  c++  java
  • 面向对象程序设计2--简单

    //

    //  main.cpp

    //  score

    //

    //  Created by duanqibo on 2019/7/12.

    //  Copyright © 2019年 duanqibo. All rights reserved.

    //  面向对象程序设计--简单

    #include <iostream>

    using namespace std;

    class student

    {

    private:

        double score;

        static double total;

        static double count;

    public:

        void scoretotalcount(double s)

        {

            score=s;

            total=total+score;

            count++;

        }

        static double sum()

        {

            return total;

        }

        static double average()

        {

            return total/count;

        }

    };

    double student::total=0;

    double student::count=0; //静态变量初始化

    int main(int argc, const char * argv[])

    {

        int n;

        double s;

        cout<<"请输入学生人数:";

        cin>>n;

        student stu;

        for(int i=0;i<n;i++)

        {

            cout<<"请输入第"<<i+1<<"个学生的分数:";

            cin>>s;

            stu.scoretotalcount(s);

        }

        cout<<"总分:"<<student::sum()<<endl;

        cout<<"平均分:"<<student::average()<<endl;

        return 1;

    }

    运行结果:

  • 相关阅读:
    森林 BZOJ 3123
    calc BZOJ 2655
    修路 BZOJ 4774
    无聊的计算器【数论多合一】
    矩阵乘法 BZOJ 2738
    K大数查询 BZOJ 3110
    发展城市 BZOJ 3700
    降雨量 BZOJ 1067
    chrome中showModalDialog解决方案
    MFC webbrowser读取文档的meta分析
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11177069.html
Copyright © 2011-2022 走看看