主题:刚学c++ 这个程序总是出问题啊 求高手帮忙改
#include"iostream.h"
#define NULL 0
struct STU
{
int number;
float score[5];
float ave;
};
float average(STU);//计算平均分
int search(int x,int number);//查找所输入学号的学生
int judge(STU,int);//判断大于等于85分的学生
void main()
{
int i,j=0;
int count=0;
int number;
char classes[5][10];//定位一个而为数组来储存科目名称
cout<<"please input the number of students\n";//输入学生数量
cin>>number;
STU *student=new STU[number];//开辟内存
cout<<"please input the names of 5 classes\n";//输入学生信息
for(i=0;i<5;i++)
cin>>classes[i];
cout<<"please input the student number and scores of 5 classes\n";
for(i=0;i<number;i++)
{
cin>>student[i].number;
for(j=0;j<5;j++)
cin>>student[i].score[j];
cin>>student[i].ave;
}
cout<<"good students follow\n";
cout<<"----------------------------------------------------------------\n";
cout<<"student_number\t";
for(i=0;i<5;i++)
{
cout<<classes[i];//输出储存科目名称
cout<<"\t";
}
cout<<"averege\n";
cout<<endl;
while(j<number)
{
student[j].ave=average(student[j]);
if(judge(student[i].score,number)==1||student[j].ave>90)
{
cout<<student[j].number<<"\t\t";
for(i=0;i<5;i++)
cout<<student[j].score[i]<<"\t";
cout<<student[j].ave;
count++;
cout<<endl;
}
j++;
}
cout<<"\n";
cout<<"----------------------------------------------------------------\n";
cout<<"there are "<<count<<" good students\n";
cout<<"----------------------------------------------------------------\n";
cout<<endl;
cout<<"input the number of student you want to search\n";
int xstudent;
cin>>xstudent;
int x=xstudent-1;
if(search(xstudent,number)==0)
cout<<"ERROR!!!";
else
{ cout<<"----------------------------------------------------------------\n";
cout<<"student_number\t";
for(i=0;i<5;i++)
{
cout<<classes[i];
cout<<"\t";
}
cout<<"averege\n";
cout<<"----------------------------------------------------------------\n";
cout<<endl;
cout<<student[x].number<<"\t\t";
for(j=0;j<5;j++)
cout<<student[x].score[j]<<"\t";
cout<<student[x].ave;
cout<<endl;
cout<<"----------------------------------------------------------------\n";
delete []student;//释放内存
}
}
float average(STU student)
{
int i;
float sum=0;
for(i=0;i<5;i++)
sum+=student.score[i];
return (sum/5);
}
int search(int xstudent,int number)
{
if(xstudent>number||xstudent<0||xstudent==0)
return 0;
else
return 1;
}
int judge(STU student[],int number)
{
int i,j;
for(i=0;i<number;i++)
for(j=0;j<5;j++)
{
if((student[i].score[j]>85)||(student[i].score[j]==85))
return 1;
else
return 0;
}
}
#define NULL 0
struct STU
{
int number;
float score[5];
float ave;
};
float average(STU);//计算平均分
int search(int x,int number);//查找所输入学号的学生
int judge(STU,int);//判断大于等于85分的学生
void main()
{
int i,j=0;
int count=0;
int number;
char classes[5][10];//定位一个而为数组来储存科目名称
cout<<"please input the number of students\n";//输入学生数量
cin>>number;
STU *student=new STU[number];//开辟内存
cout<<"please input the names of 5 classes\n";//输入学生信息
for(i=0;i<5;i++)
cin>>classes[i];
cout<<"please input the student number and scores of 5 classes\n";
for(i=0;i<number;i++)
{
cin>>student[i].number;
for(j=0;j<5;j++)
cin>>student[i].score[j];
cin>>student[i].ave;
}
cout<<"good students follow\n";
cout<<"----------------------------------------------------------------\n";
cout<<"student_number\t";
for(i=0;i<5;i++)
{
cout<<classes[i];//输出储存科目名称
cout<<"\t";
}
cout<<"averege\n";
cout<<endl;
while(j<number)
{
student[j].ave=average(student[j]);
if(judge(student[i].score,number)==1||student[j].ave>90)
{
cout<<student[j].number<<"\t\t";
for(i=0;i<5;i++)
cout<<student[j].score[i]<<"\t";
cout<<student[j].ave;
count++;
cout<<endl;
}
j++;
}
cout<<"\n";
cout<<"----------------------------------------------------------------\n";
cout<<"there are "<<count<<" good students\n";
cout<<"----------------------------------------------------------------\n";
cout<<endl;
cout<<"input the number of student you want to search\n";
int xstudent;
cin>>xstudent;
int x=xstudent-1;
if(search(xstudent,number)==0)
cout<<"ERROR!!!";
else
{ cout<<"----------------------------------------------------------------\n";
cout<<"student_number\t";
for(i=0;i<5;i++)
{
cout<<classes[i];
cout<<"\t";
}
cout<<"averege\n";
cout<<"----------------------------------------------------------------\n";
cout<<endl;
cout<<student[x].number<<"\t\t";
for(j=0;j<5;j++)
cout<<student[x].score[j]<<"\t";
cout<<student[x].ave;
cout<<endl;
cout<<"----------------------------------------------------------------\n";
delete []student;//释放内存
}
}
float average(STU student)
{
int i;
float sum=0;
for(i=0;i<5;i++)
sum+=student.score[i];
return (sum/5);
}
int search(int xstudent,int number)
{
if(xstudent>number||xstudent<0||xstudent==0)
return 0;
else
return 1;
}
int judge(STU student[],int number)
{
int i,j;
for(i=0;i<number;i++)
for(j=0;j<5;j++)
{
if((student[i].score[j]>85)||(student[i].score[j]==85))
return 1;
else
return 0;
}
}