# Design of score statistics system

2022-02-02 19:50:57

Enter students' test scores in each subject , Calculate the average score of each student , Output each student's test scores and individual average scores , Calculate and output the average score of each subject 、 The highest 、 Lowest score 、 pass rate ( Choose... For yourself 2 Outputs ), Rank according to the students' overall evaluation results and output the ranking .

``#include<cstring>#include<iostream>#include<map>using namespace std;class Stu {    public:        int id;        float math;        float english;        float chinese;        float sum;            Stu(float ma,float eng,float ch,float s)        {            math = ma;            english = eng;            chinese = ch;            sum = s;        };        float pj();        void print_s(float sum);        void sum1();};float Stu::pj(){    float pjsorce = 0;    pjsorce = (math + english + chinese) / 3;    return pjsorce;}void Stu::print_s(float s){    cout << " Scores of different branches （ mathematics , English , Chinese language and literature ）：" << math << " " << english << " " << chinese << endl;    cout << " Individual average score ：" << sum/3 << endl;}void Stu::sum1(){    sum = math + english + chinese;}int main(){    Stu s1(86, 56, 70, 0);    Stu s2(46, 89, 23, 0);    Stu s3(69, 69, 99, 0);    Stu s4(56, 99, 99, 0);    s1.sum1();    s2.sum1();    s3.sum1();    s4.sum1();    cout << "-----------------------" << endl;    float sum2 = s1.pj();    s1.print_s(sum2);    float sum3 = s2.pj();    s2.print_s(sum2);    float sum4 = s3.pj();    s3.print_s(sum2);    float sum5 = s4.pj();    s4.print_s(sum2);    cout << "-----------------------" << endl;    //  Average score of each subject     float math_a = (s1.math + s2.math + s3.math + s4.math) / 4;    float english_a = (s1.english + s2.english + s3.english + s4.english) / 4;    float chinese_a = (s1.chinese + s2.chinese + s3.chinese + s4.chinese) / 4;    cout << " The math average ：" << math_a << endl;    cout << " Average score of English ：" << english_a << endl;    cout << " Average score of Chinese ：" << chinese_a << endl;    cout << "-----------------------" << endl;    // The highest  &  Lowest score     float m[4] = {s1.math,s2.math,s3.math,s4.math};    float e[4] = {s1.english,s2.english,s3.english,s4.english};    float c[4] = {s1.chinese,s2.chinese,s3.chinese,s4.chinese};    float math_max = m[0], math_min = m[0];    float english_max = e[0], english_min = e[0];    float chinese_max = c[0], chinese_min = c[0];    float ma = 0, en = 0, ch =0;    //  pass rate     for(int i=0; i<4; i++)    {        //  mathematics         if(m[i] > math_max && i != 0)        {            math_max = m[i];        }        if(m[i] < math_min && i != 0)        {            math_min = m[i];        }        if(m[i] >= 60)        {            ma++;        }        //  English         if(e[i] > english_max && i != 0)        {            english_max = e[i];        }        if(e[i] < english_min && i != 0)        {            english_min = e[i];        }        if(e[i] >= 60)        {            en++;        }        //  Chinese language and literature         if(c[i] > chinese_max && i != 0)        {            chinese_max = c[i];        }        if(c[i] < chinese_min && i != 0)        {            chinese_min = c[i];        }        if(c[i] >= 60)        {            ch++;        }    }    ma = ma / 4;    en = en / 4;    ch = ch / 4;    cout << " The highest score in math ：" << math_max << ", Lowest score ：" << math_min << ", pass rate ：" << ma << endl;    cout << " The highest score in English ：" << english_max << ", Lowest score ：" << english_min << ", pass rate ：" << en << endl;    cout << " The highest score in Chinese ：" << chinese_max << ", Lowest score ：" << chinese_min << ", pass rate ：" << ch << endl;    cout << "-----------------------" << endl;    //  ranking         float sum[4] = {s1.sum,s2.sum,s3.sum,s4.sum};    for(int i=0; i<4; i++)    {        for(int j=i+1; j < 4; j++)        {            if(sum[i] <= sum[j])            {                float temp = sum[i];                sum[i] = sum[j];                sum[j] = temp;            }        }    }    cout << " ranking （ High to low ）: ";    for(int i=0; i<4; i++)    {        cout << sum[i] << " ";     }    cout << endl;    cout << "-----------------------" << endl;    return 0;}``