7-1クラス全員のC++課程の総成績と平均成績(10点)を計算する

4223 ワード

クラスStudioを定義し、学生C++コースの成績を記録します.静的データメンバーまたは静的メンバー関数を使用して、クラス全員のC++カリキュラムの合計成績と平均成績を計算する必要があります.
入力形式:C++の成績として、100を超えない正の整数を5個入力します.
出力フォーマット:1行目に成績の和を出力し、2行目に平均成績を出力します.
入力サンプル:90 80,70,60,50出力サンプル:350,70
#include
using namespace std;
class Student{
    int score;
    static int total;
public:
    Student(int s=0):score(s){
        total+=s;
    }
    static void display();
};
int Student::total=0;
void Student::display(){
    cout<<total<<endl<<total/5;
}
int main(){
    int score;
    for(int i=0;i<5;i++){
        cin>>score;
        Student s(score);//        for   ,         ,    
    }Student s;
    s.display();
    return 0;
}