推選答案#include <iostream>
#include <string>
using namespace std;#define max 20typedef struct _Student{
string name;
string id;
float math, com, eng, total; //對(duì)應(yīng)為數(shù)學(xué),計(jì)算機(jī),英語(yǔ),總分
}Student;void search(Student data[]){ //找人并顯示
string id;
cout<<"\n輸入學(xué)生學(xué)號(hào): ";
cin>>id;
for (int i=0; i<max; i++){
if (id == data[i].id){
cout<<endl
<<"姓名 : "<<data[i].name<<endl
<<"學(xué)號(hào) : "<<data[i].id<<endl
<<"數(shù)學(xué) : "<<data[i].math<<endl
<<"英語(yǔ) : "<<data[i].eng<<endl
<<"計(jì)算機(jī): "<<data[i].com<<endl
<<"總分 : "<<data[i].total<<endl<<endl;
return;
}
}
cout<<endl

<<"沒(méi)有找到學(xué)號(hào)為: "<<id<<" 的學(xué)生"<<endl;
}void copyStudent(Student* a, Student* b){//把B復(fù)制給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)計(jì)
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ù)學(xué)不及格 : "<<fMath<<endl

<<"英語(yǔ)不及格 : "<<fEng<<endl
<<"計(jì)算機(jī)不及格: "<<fCom<<endl<<endl;
}void input(Student data[]){//輸入數(shù)據(jù)
int i=0;
char c;
do{
cout<<endl
<<"輸入姓名: ";
cin>>data[i].name;
cout<<"輸入學(xué)號(hào): ";
cin>>data[i].id;
cout<<"輸入數(shù)學(xué)課成績(jī): ";
cin>>data[i].math;
cout<<"輸入英語(yǔ)課成績(jī): ";
cin>>data[i].eng;
cout<<"輸入計(jì)算機(jī)課成績(jī): ";
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
<<"學(xué)號(hào) :"<<data[i].id<<endl
<<"數(shù)學(xué) :"<<data[i].math<<endl
<<"英語(yǔ) :"<<data[i].eng<<endl
<<"計(jì)算機(jī):"<<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;
}