实验3.2

流程图

 

#include<iostream>
#include<string>
using namespace std;
class StudentScore {
public:
    StudentScore()
    {
        student_nr = 2;
    }
    StudentScore(int student_count)
    {
        student_nr = student_count;
    }
    void InputStudentNameAndScore()
    {
        for (int student_id = 0; student_id < student_nr; student_id++)

        {
            cout << "输入学生姓名:" << endl;
            cin >> name_array[student_id];
            cout <<"输入科目A成绩:" << endl;
            cin >> score_table[student_id][1];
            cout << "输入科目B成绩:" << endl;
            cin >> score_table[student_id][2];
            cout << "输入科目C成绩:" << endl;
            cin >> score_table[student_id][3];
        }
    }
    void ShowStudentNameAndScore()
    {
        for (int student_id = 0; student_id < student_nr; student_id++)
        {
            cout << "姓名:" << name_array[student_id] << "科目A成绩:" << score_table[student_id][1] << "科目B成绩:" << score_table[student_id][2]
                << "科目C成绩:" << score_table[student_id][3] << endl;

        }
    }
    void ShowStdentAvgScore(int student_id)
    {
        float average;
        average = (score_table[student_id][1] + score_table[student_id][2] + score_table[student_id][3]) / 3;
        cout << average << endl;
    }
    void ShowCourseAvgScore(string course_name)
    {
        if (course_name == "A")
        {
            float avg_A = 0;
            for (int student_id = 0; student_id < student_nr; student_id++)
            {
                avg_A = avg_A + score_table[student_id][1];
            }
            avg_A = avg_A / student_nr;
            cout << "A科目平均成绩:" << endl;
            cout << avg_A << endl;
        }
        if (course_name == "B")
        {
            float avg_B = 0;
            for (int student_id = 0; student_id < student_nr; student_id++)
            {
                avg_B = avg_B + score_table[student_id][2];
            }
            avg_B = avg_B / student_nr;
            cout << "B科目平均成绩:" << endl;
            cout << avg_B << endl;
        }
        if (course_name == "C")
        {
            float avg_C = 0;
            for (int student_id = 0; student_id < student_nr; student_id++)
            {
                avg_C = avg_C + score_table[student_id][3];
            }
            avg_C = avg_C / student_nr;
            cout << "C科目平均成绩:" << endl;
            cout << avg_C << endl;
        }
    }
    void OrderScoreByCourse(string course_name)
    {

        if (course_name == "A")
        {
            int ta = 0;
            for (int student_id = 0; student_id < student_nr - 1; student_id++)
            {
                for (int j = 0; j < student_nr - 1 - j; j++)
                {
                    if (score_table[j][1] < score_table[j + 1][1])
                    {
                        ta = score_table[j][1];
                        score_table[j][1] = score_table[j + 1][1];
                        score_table[j + 1][1] = ta;
                    }
                }
            }
            cout << "排序为:" << endl;
            for (int student_id = 0; student_id < student_nr; student_id++)
                cout << score_table[student_id][1] << endl;
        }
        if (course_name == "B")
        {
            int ta = 0;
            for (int student_id = 0; student_id < student_nr - 1; student_id++)
            {
                for (int j = 0; j < student_nr - 1 - j; j++)
                {
                    if (score_table[j][2] < score_table[j + 1][2])
                    {
                        ta = score_table[j][2];
                        score_table[j][2] = score_table[j + 1][2];
                        score_table[j + 1][2] = ta;
                    }
                }
            }
            cout << "排序为:" << endl;
            for (int student_id = 0; student_id < student_nr; student_id++)
                cout << score_table[student_id][2] << endl;
        }
        if (course_name == "C")
        {
            int ta = 0;
            for (int student_id = 0; student_id < student_nr - 1; student_id++)
            {
                for (int j = 0; j < student_nr - 1 - j; j++)
                {
                    if (score_table[j][3] < score_table[j + 1][3])
                    {
                        ta = score_table[j][3];
                        score_table[j][3] = score_table[j + 1][3];
                        score_table[j + 1][3] = ta;
                    }
                }
            }
            cout << "排序为:" << endl;
            for (int student_id = 0; student_id < student_nr; student_id++)
                cout << score_table[student_id][3] << endl;
        }
    }
private:
    float score_table[100][3], score_sorting[100];
    string name_array[100], name_sorting[100];
    int student_nr;
};
int main()
{
    StudentScore x;
    x.InputStudentNameAndScore();
    x.ShowStudentNameAndScore();
    x.ShowStdentAvgScore(1);
    x.ShowCourseAvgScore("A");
    x.OrderScoreByCourse("B");
    return 0;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值