排序有问题,说是访问冲突,麻烦大家看下
昨晚写的个学生成绩管理系统,错误一大堆。。自己没找出来,好像全是访问冲突方面的,麻烦大家帮忙看下吧#include<iostream>
#include <stdlib.h>
using namespace std;
struct student
{
int num;
char name[20];
float score[3];
float average;
struct student *next;
};
student *head;
student *set()
{
static student *p=head;
student *l;
l=new student;
l->next=NULL;
p->next=l;
p=p->next;
return p;
}
ostream &operator <<(ostream &out,const student *Q)
{
out<<"\n学号:"<<Q->num<<"\n姓名:"<<Q->name;
int i;
for(i=0;i<3;i++)
{
out<<"第"<<i+1<<"门成绩"<<Q->score[i];
}
if(Q->average!=0)
out<<"平均成绩:"<<Q->average<<endl;
else
out<<endl;
return out;
}
void display()
{
student *h;
h=head;
do{
cout<<h<<endl;
if(h->next==NULL) break;
h=h->next;
}while(1);
}
void show()
{
student *h;
h=head;
int m=0;
do{
int j=0;
for(int i=0;i<3;i++)
{
if(h->score[i]<60) { j=1;m=1; break;}
}
if(j)
{
cout<<h<<endl;
}
if((h->next)==NULL)
{break;}
h=h->next;
}while(1);
if(!m)
{
cout<<"没有不及格的同学"<<endl;
}
}
void avae()
{
student *h;
h=head;
do{
float sum=0;
for(int i=0;i<3;i++)
{
sum+=h->score[i];
}
h->average=sum/3;
if((h->next)==NULL)
{ break;}
h=h->next;
}while(1);
}
int lon()
{
student *h;
h=head;
int i;
for(i=1;1;i++)
{
if(h->next==NULL)
{ break;}
h=h->next;
}
return i;
}
void turn()
{
student *h,*h_0,*h_1;
int m=lon();
if(m<3)
{
h=head;
h_0=head->next;
if(h->average>h_0->average)
{
head=h_0;
h_0->next=h;
h->next=NULL;
}
}
else if(m>2)
{
for(;m>0;m--)
{
h=head;
h_0=h->next;
h_1=h_0->next;
int i;
for(i=0;i<m;i++)
{
if(h_0->average>h_1->average)
{
h->next=h_1;
h_0->next=h_1->next;
h_1->next=h_0;
}
if(h_1->next==NULL)
{ break; }
h=h->next;
h_0=h_0->next;
h_1=h_1->next;
}
}
}
}
void dele(int num1)
{
student *h;
student *h_0;
h=head->next;
h_0=head;
if((h_0->num)==num1)
{
head=h;
delete h_0;
}
else
do{
if((h->num)==num1)
{
(h_0->next)=(h->next);
delete h;
break;
}
if((h->next)==NULL)
{ break; }
h_0->next=h;
h=h->next;
}while(1);
}
int main()
{
student *h;
loop_0:
cout<<"学生成绩管理系统\n 1、成绩录入\n2、查看成绩\n3、成绩查询\n";
cout<<"4、成绩统计\n5、增加成绩\n6、删除成绩\n7、退出\n请选择:"<<endl;
int change;
int change_0;
cin>>change;
system("cls");
switch(change)
{
case 1:
{
head=h=new student;
h->next=NULL;
do{
cout<<"请输入学号";
cin>>h->num;
system("cls");
cout<<"请输入姓名";
cin>>h->name;
system("cls");
for(int i=0;i<3;i++)
{
cout<<"请输入第"<<i+1<<"门课成绩";
cin>>h->score[i];
system("cls");
}
cout<<"返回主菜单请输入0,继续输入请输入1:"<<endl;
cin>>change_0;
system("cls");
if(change_0==0)
{
goto loop_0;
}
h=set();
}while(change_0);
}
case 2:
{
display();
system("pause");
system("cls");
goto loop_0;
break;
}
case 3:
{
loop_1:
cout<<"1、按学号查询\n2、查询不及格学生记录";
int change_1;
void inquire(int nums);
cin>>change_1;
system("cls");
if(change_1==1)
{
cout<<"请输入学号:"<<endl;
int num;
cin>>num;
system("cls");
inquire(num);
cout<<"返回主菜单请输入0,重新查询请输入1:";
cin>>change_0;
system("cls");
if(change_0==0)
{
goto loop_0;
}
else if(change_0==1)
{
goto loop_1;
}
}
else if(change_1==2)
{
show();
cout<<"返回主菜单请输入0,重新查询请输入1:";
cin>>change_0;
system("cls");
if(change_0==0)
{
goto loop_0;
}
else if(change_0==1)
{
goto loop_1;
}
}
else
{
cout<<"输入错误请重新输入:"<<endl;
system("cls");
goto loop_1;
}
break;
}
case 4:
{
avae();
turn();
display();
system("pause");
system("cls");
goto loop_0;
break;
}
case 5:
{
do{
h=set();
cout<<"请输入学号";
cin>>h->num;
system("cls");
cout<<"请输入姓名";
cin>>h->name;
system("cls");
for(int i=0;i<3;i++)
{
cout<<"请输入第"<<i+1<<"门课成绩";
cin>>h->score[i];
system("cls");
}
cout<<"返回主菜单请输入0,继续输入请输入1:"<<endl;
cin>>change_0;
system("cls");
if(change_0==0)
{
goto loop_0;
}
}while(change_0);
}
case 6:
{
int num1;
do{
cout<<"请输入您要删除数据的学号:"<<endl;
cin>>num1;
dele(num1);
system("cls");
cout<<"返回主菜单请输入0,继续输入请输入1:"<<endl;
cin>>change_0;
system("cls");
if(change_0==0)
{
goto loop_0;
}
}while(change_0);
}
case 7:
break;
default:
{
cout<<"输入错误,请重新输入";
system("cls");
goto loop_0;
}
}
cout<<"谢谢使用"<<endl;
student *h_0=head;
h=head->next;
student *h_1;
if(lon()>=3)
{
do{
h_1=h_0;
h_0=(h_0->next);
h=h->next;
delete h_0;
if((h->next)==NULL)
{
delete h_1;
delete h;
break;
}
}while(1);
}
else
{
delete h;
delete h_0;
}
return 0;
}
void inquire(int nums)
{
student *h;
h=head;
do{
if(nums==(h->num))
{
cout<<h<<endl;
break;
}
if((h->next)==NULL)
{
cout<<"您输入的学号有误"<<endl;
break;
}
h=(h->next);
}while(1);
}