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;

    }

    运行结果:

  • 相关阅读:
    1046 A^B Mod C
    1019 逆序数
    1012 最小公倍数LCM
    1011 最大公约数GCD
    序列化
    bigdecimal
    equals 和hashcode
    java多线程-读写锁原理
    Java并发编程:volatile关键字解析
    面试
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11177069.html
Copyright © 2011-2022 走看看