PTA:计算全班学生C++课程的总成绩和平均成绩(c++,静态成员)

定义一个类Student,记录学生C++课程的成绩。要求使用静态数据成员或静态成员函数计算全班学生C++课程的总成绩和平均成绩。
输入格式:
输入5个不超过100的正整数,作为C++成绩。
输出格式:
在第一行中输出成绩的和,第二行输出平均成绩。
输入样例:
90 80 70 60 50

输出样例:
350

#include<bits/stdc++.h>
using namespace std;
class Student{
    protected:
    int cpp_score;
    static int sum;
    static double avg;
    public:
    Student(){};
    Student(int a):cpp_score(a){
        sum+=a;
        avg=sum/5;
    };
    void disp(){
        cout<<sum<<endl;
        cout<<avg;
    }
};
int Student::sum=0;
double Student::avg=0;
int main(){
    int score;
    Student *p;
    int count=0;
    for(int i=0;i<5;i++){
        cin>>score;
        p=new Student(score);
    }
    p->disp();
    //system("pause");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值