#include<iostream>//202130310291
#include<string.h>
using namespace std;
class Coordinate {
public:
Coordinate(int times1 = 2)
{
times = times1;
}
void InputCoord()
{
for (int i = 0; i < times; i++)
{
cout << "请输入学生姓名:" << endl;
cin >> name[i];
cout << "请输入科目A成绩:" << endl;
cin >> Coord[i][0];
cout << "请输入科目B成绩:" << endl;
cin >> Coord[i][1];
cout << "请输入科目C成绩:" << endl;
cin >> Coord[i][2];
}
}
void ShowCoord()
{
for (int i = 0; i < times; i++)
{
cout << "姓名:" << name[i] << " 科目A成绩:" << Coord[i][0] << " 科目B成绩" << Coord[i][1] << " 科目C成绩" << Coord[i][2] << endl;
}
}
void ShowAvgCoord()
{
float avgA = 0;
float avgB = 0;
float avgC = 0;
for (int i = 0; i < times; i++)
{
avgA = avgA + Coord[i][0];
avgB = avgB + Coord[i][1];
avgC = avgC + Coord[i][2];
avg[i] = Coord[i][0] + Coord[i][1] + Coord[i][2];
}
avgA = avgA / times;
avgB = avgB / times;
avgC = avgC / times;
for (int i = 0; i < times; i++)
{
cout << "姓名:" << name[i] << "平均成绩:" << avg[i] << endl;
}
cout << "课程名称:A 平均成绩:" << avgA << endl;
cout << "课程名称:B 平均成绩:" << avgB << endl;
cout << "课程名称:C 平均成绩:" << avgC << endl;
}
void sort()
{
for (int i = 0; i < times - 1; i++) {
for (int j = 0; j < times - 1 - i; j++) {
if (avg[j] > avg[j + 1])
{
float temp = avg[j + 1];
avg[j + 1] = avg[j];
avg[j] = temp;
char temp1[100][20];
strcpy_s(temp1[0], name[j + 1]);
strcpy_s(name[j + 1] , name[j]);
strcpy_s(name[j] , temp1[0]);
}
}
}
for (int i = 0; i < times; i++)
{
cout << "姓名:" << name[i] << " 平均成绩:" << avg[i] << endl;
}
}
};
private:
float Coord[100][300];
int times;
char name[100][20];
float avg[100];
int main()
{
Coordinate x(2);
x.InputCoord();
x.ShowCoord();
x.ShowAvgCoord();
x.sort();
return 0;
}