学生信息管理
![](https://i-blog.csdnimg.cn/blog_migrate/826e07d05e99a6c157a2ec0aa85b27d3.png)
#include <iostream>
using namespace std;
#include <string>
struct LinkNode {
int s_num;
string s_name;
double s_garde1;
double s_garde2;
double s_garde3;
double jun_zhi;
LinkNode* link;
LinkNode() {
link = NULL;
}
LinkNode(int num, string name, double n1, double n2, double n3) {
s_num = num;
s_name = name;
s_garde1 = n1;
s_garde2 = n2;
s_garde3 = n3;
jun_zhi = (n1 + n2 + n3) / 3;
link = NULL;
}
};
template <class T>
class LineList {
public:
int length;
LinkNode* first;
public:
LineList() {}
LineList(int n) {
length = n;
first = new LinkNode();
LinkNode* current = first;
for (int i = 0; i < length; i++) {
int num;
string name;
double n1, n2, n3;
cin >> num;
cin >> name;
cin >> n1 >> n2 >> n3;
LinkNode* newnode = new LinkNode(num,name,n1,n2,n3);
current->link = newnode;
current = newnode;
}
}
void Sort() {
LinkNode* current = first;
LinkNode* p;
LinkNode* q;
for (p = current->link; p != NULL; p = p->link)
{
for (q = p->link; q != NULL; q = q->link) {
if (p->jun_zhi < q->jun_zhi)
{
int tmp = q->s_num;
q->s_num = p->s_num;
p->s_num = tmp;
string tmp2 = q->s_name;
q->s_name = p->s_name;
p->s_name = tmp2;
double tmp3 = q->s_garde1;
q->s_garde1 = p->s_garde1;
p->s_garde1 = tmp3;
double tmp4 = q->s_garde2;
q->s_garde2 = p->s_garde2;
p->s_garde2 = tmp4;
double tmp5 = q->s_garde3;
q->s_garde3 = p->s_garde3;
p->s_garde3 = tmp5;
double tmp6 = q->jun_zhi;
q->jun_zhi = p->jun_zhi;
p->jun_zhi = tmp6;
}
}
}
}
void Print() {
LinkNode* current = first;
for (int i = 1; i <= length; i++) {
current = current->link;
cout.precision(2);
cout << current->s_num << " " << fixed
<< current->s_name << " " << fixed
<< current->s_garde1 << " " << fixed
<< current->s_garde2 << " " << fixed
<< current->s_garde3 << " " << fixed
<< current->jun_zhi << " " << i << endl;
}
cout << endl;
}
};
int main() {
int n;
cin >> n;
LineList<double> L(n);
L.Sort();
L.Print();
}