#include <iostream>
#include <string>
using namespace std;#define max 20typedef struct _Student{
string name;
string id;
float math, com, eng, total; //对应为数学,计算机,英语,总分
}Student;void search(Student data[]){ //找人并显示
string id;
cout<<"\n输入学生学号: ";
cin>>id;
for (int i=0; i<max; i++){
if (id == data[i].id){
cout<<endl
<<"姓名 : "<<data[i].name<<endl
<<"学号 : "<<data[i].id<<endl
<<"数学 : "<<data[i].math<<endl
<<"英语 : "<<data[i].eng<<endl
<<"计算机: "<<data[i].com<<endl
<<"总分 : "<<data[i].total<<endl<<endl;
return;
}
}
cout<<endl
<<"没有找到学号为: "<<id<<" 的学生"<<endl;
}void copyStudent(Student* a, Student* b){//把B复制给A
a->name = b->name;
a->id = b->id;
a->math = b->math;
a->eng = b->eng;
a->com = b->com;
a->total = b->total;
}
void sort(Student data[]){//排序
for(int i=0; i<max-1; i++){
for (int j=0; j<max-1; j++){
if (data[j].total < data[j+1].total){
Student temp;
copyStudent(&temp, &data[j]);
copyStudent(&data[j],&data[j+1]);
copyStudent(&data[j+1],&temp);
}
}
}
}void statistics(Student data[]){//统计
int fMath=0, fEng=0, fCom=0;
for (int i=0; i<max; i++){
if (data[i].math < 60.f)
fMath++;
if (data[i].eng < 60.f)
fEng++;
if (data[i].com < 60.f)
fCom++;
}
cout<<endl
<<"数学不及格 : "<<fMath<<endl
<<"英语不及格 : "<<fEng<<endl
<<"计算机不及格: "<<fCom<<endl<<endl;
}void input(Student data[]){//输入数据
int i=0;
char c;
do{
cout<<endl
<<"输入姓名: ";
cin>>data[i].name;
cout<<"输入学号: ";
cin>>data[i].id;
cout<<"输入数学课成绩: ";
cin>>data[i].math;
cout<<"输入英语课成绩: ";
cin>>data[i].eng;
cout<<"输入计算机课成绩: ";
cin>>data[i].com;
data[i].total = (data[i].math + data[i].eng + data[i].com)/3.f;
i++;
cout<<"继续? (y/n): ";
cin>>c;
}while (i<max && ( c== 'y' || c== 'Y'));
}void displayAll(Student data[]){//显示全部
for (int i=0; i<max; i++){
if (data[i].total != -1){
cout<<endl
<<"#"<<i+1<<endl
<<"姓名 :"<<data[i].name<<endl
<<"学号 :"<<data[i].id<<endl
<<"数学 :"<<data[i].math<<endl
<<"英语 :"<<data[i].eng<<endl
<<"计算机:"<<data[i].com<<endl
<<"总分 :"<<data[i].name<<endl<<endl;
}
}
}void init(Student data[]){
for (int i=0; i<max; i++){
data[i].name = " ";
data[i].id = " ";
data[i].math = 100.f;
data[i].eng = 100.f;
data[i].com = 100.f;
data[i].total = -1.f;
}
}int main(){
Student data[max];
init(data);
input(data);
sort(data);
displayAll(data);
statistics(data);
return 0;
}



