成绩统计(C++)

【问题描述】

某天,教务处要统计学生的C++成绩。

    假设你是计算机某班的班长,现在已经知道了所有学生的学号,姓名,C++成绩,统计你班学生的人数与你班C++的平均成绩。请定义一个名为Student的类,其中,用成员数据myID来记录学生id,myName来记录学生姓名,myScore来记录学生成绩,并用静态成员数据classSize记录班级人数和静态成员数据totalScore记录总成绩,编写静态成员函数getNum()来统计班级人数,静态成员函数getAverage()来计算平均成绩。

#include  <iostream>
#include  <string>
using  namespace  std;

class  Student{
private:
    string myID;
    string myName;
    int myScore;
public:
    Student(string id, string name, int score);
    static int classSize;
    static int totalScore;
    static int getNum();
    static double getAverage();
};

Student::Student(string id, string name, int score) {
    myID = id;
    myName = name;
    myScore = score;
    classSize++;
    totalScore += score;
}

int Student::getNum() {
    return classSize;
}

double Student::getAverage() {
    return (double) totalScore / classSize;
}

int  Student::classSize=0;
int  Student::totalScore=0;

int  main()
{
    string  id,  name;
    int  score;
    cout  <<  "Please  input  the  information  of  a  student:  (id,  name  and  score).  Press  Ctrl+Z  to  stop."  <<  endl;
    while(cin>>id>>name>>score){
        Student  stu(id,  name,  score);
    }
    cout<<Student::getNum()<<"  "<<Student::getAverage()<<endl;
    return  0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

*OASIS*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值