Question:
Count students and scores
Problem description
Define a student class to record the student's student ID and C ++ course score. Static member variables and static member functions are required to calculate the total score and average score of the class C ++ course.
Input
Enter the student ID and score, and each student's information occupies a row until the end of the file.
The output consists of two rows. The first row contains the total number of students and the total score, which are separated by spaces;
The average score of the second row.
Sample Input
101 30102 50103 90104 60105 70
Sample output
5 30060
Reference code:
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;class Student{private: int id, score; static int count; static int sum;public: Student(int i, int s); Student(const Student&); ~Student(); static void show();};Student::Student(int i, int s){ id = i; score = s; count++; sum += score;}Student::Student(const Student& c){ id = c.id; score = c.score;}Student::~Student(){}void Student::show(){ cout << count << " " << sum << endl; cout << (double)(1.0 * sum / count) << endl;}int Student::count = 0;int Student::sum = 0;int main(){ //freopen("1.txt", "r", stdin); int id, score; while (cin >> id >> score) Student x(id, score); Student::show(); return 0;}