#include <iostream>
#include<string>
using namespace std;
class StudentScore {
public:
StudentScore()
{
student_nr = 2;
}
StudentScore(int student_count)
{
student_nr = student_count;
}
void InputStudentNameAndScore();
void ShowStudentNameAndSore();
void ShowStudentAvgScore(int student_id);
void ShowCourseAvgScore(string course_name);
void OrderScoreByCourse(string course_name);
private:
float score_table[100][3];
string name_attay[100];
int student_nr;
};
void StudentScore::InputStudentNameAndScore()
{
for (int i = 0; i < student_nr; i++)
{
cout << "请输入学生的姓名:" << endl;
cin >> name_attay[i];
cout << "请输入科目A的成绩:" << endl;
cin >> score_table[i][1];
cout << "请输入科目B的成绩:" << endl;
cin >> score_table[i][2];
cout << "请输入科目C的成绩:" << endl;
cin >> score_table[i][3];
}
}
void StudentScore::ShowStudentNameAndSore()
{
for (int i = 0; i < student_nr; i++)
{
cout << "姓名:" << name_attay[i] << "科目A的成绩:" << score_table[i][1] << "科目B的成绩:" << score_table[i][2] << "科目C的成绩:" << score_table[i][3] << endl;
}
}
void StudentScore::ShowStudentAvgScore(int student_id)
{
for (int i = 0; i < student_nr; i++)
{
float avg = 0;
avg = score_table[i][1] + score_table[i][2] + score_table[i][3];
avg = avg / 3;
cout << "姓名" << name_attay[i] << "平均成绩:" << avg << endl;
}
}
void StudentScore::ShowCourseAvgScore(string course_name)
{
float avga = 0;
float avgb = 0;
float avgc = 0;
for (int i = 0; i < student_nr; i++)
{
avga = avga + score_table[i][1];
avgb = avgb + score_table[i][2];
avgc = avgc + score_table[i][3];
}
avga = avga / student_nr;
avgb = avgb / student_nr;
avgc = avgc / student_nr;
cout << "课程名称:A 平均成绩" << avga << endl;
cout << "课程名称:B 平均成绩" << avgb << endl;
cout << "课程名称:C 平均成绩" << avgc << endl;
}
void StudentScore::OrderScoreByCourse(string course_name)
{
for (int j = 1; j <4; j++)
{
float w;
for (int i = 0; i < student_nr; i++)
{
if (score_table[i + 1][j] > score_table[i][j])
{
w = score_table[i + 1][j];
score_table[i + 1][j] = score_table[i][j];
score_table[i][j] = w;
}
}
}
cout << "课程A的成绩排序:";
for (int i = 0; i < student_nr; i++)
cout << score_table[i][1] << " ";
cout << endl;
cout << "课程B的成绩排序:";
for (int i = 0; i < student_nr; i++)
cout << score_table[i][2] << " ";
cout << endl;
cout << "课程C的成绩排序:";
for (int i = 0; i < student_nr; i++)
cout << score_table[i][3] << " ";
cout << endl;
}
int main()
{
StudentScore y;
y.InputStudentNameAndScore();
y.ShowStudentNameAndSore();
y.ShowStudentAvgScore(1);
y.ShowCourseAvgScore("A");
y.OrderScoreByCourse("B");
return 0;
}