*定义结构体存学生姓名和分数,把分数大于平均分的,放到另一个数组里面
#include <iostream>
#include <stdlib.h>
using namespace std;
float score_ave=0;
typedef struct stu
{
int num;
string name;
float score;
stu *next;
};
void save(stu *x,stu *H)
{
if(x->score>score_ave)
{
stu *p=new stu;
p->next=H->next;
H->next=p;
p->name=x->name;
p->num=x->num;
p->score=x->score;
}
}
int main()
{
void save(stu *x,stu *H);
stu *H1=new stu;
stu *H2=new stu;
H1->next=NULL;
H2->next=NULL;
char k;
int N=0;
do{
stu *p=new stu;
cout <<"请输入"<<endl;
cin>>p->name;
cin>>p->num;
cin>>p->score;
score_ave+=p->score;
p->next=H1->next;
H1->next=p;
cout<<"是否继续输入"<<endl;
cout << endl;
cin>>k;
cout << endl;
N++;
}while(k!='#');
score_ave=score_ave/N;
cout << "输出平均分"<< score_ave << endl;
stu *p=H1->next;
while(p!=NULL){
save(p,H2);
p=p->next;
}
p=H2->next;
while(p!=NULL){
cout<<p->name<<endl<<p->num<<endl<<p->score<<endl;
p=p->next;
}
p=H1;
while(p!=NULL){
stu *q=p;
p=p->next;
delete q;
}
p=H2;
while(p!=NULL){
stu *q=p;
p=p->next;
delete q;
}
return 0;
}
return 0;
}