推選答案#include <iostream>
#include <string>
using namespace std;#define max 20typedef struct _Student{
string name;
string id;
float math, com, eng, total; //對應為數(shù)學,計算機,英語,總分
}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
<<"數(shù)學 : "<<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[]){//統(tǒng)計
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
<<"數(shù)學不及格 : "<<fMath<<endl

<<"英語不及格 : "<<fEng<<endl
<<"計算機不及格: "<<fCom<<endl<<endl;
}void input(Student data[]){//輸入數(shù)據(jù)
int i=0;
char c;
do{
cout<<endl
<<"輸入姓名: ";
cin>>data[i].name;
cout<<"輸入學號: ";
cin>>data[i].id;
cout<<"輸入數(shù)學課成績: ";
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<<"繼續(xù)? (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
<<"數(shù)學 :"<<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;
}