| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 938 人关注过本帖
标题:排序有问题,说是访问冲突,麻烦大家看下
取消只看楼主 加入收藏
o0慢节奏0o
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:6 
排序有问题,说是访问冲突,麻烦大家看下
昨晚写的个学生成绩管理系统,错误一大堆。。自己没找出来,好像全是访问冲突方面的,麻烦大家帮忙看下吧
#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);
 }
搜索更多相关主题的帖子: 麻烦 访问 
2010-06-29 16:07
o0慢节奏0o
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-28
收藏
得分:0 
回复 楼主 o0慢节奏0o
倒数第二个函数是主函数
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;
}
2010-06-29 16:54
o0慢节奏0o
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-28
收藏
得分:0 
回复 4楼 qiangyongshe
定义什么
2010-06-29 17:14
o0慢节奏0o
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-28
收藏
得分:0 
有人会没 麻烦大家帮个忙 谢谢
2010-06-29 23:51
o0慢节奏0o
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-28
收藏
得分:0 
回复 7楼 lintaoyn
应该怎么检查 能不能举个例子 刚学C++没多久 这方面不太了解
2010-06-30 10:03
o0慢节奏0o
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-28
收藏
得分:0 
回复 9楼 lintaoyn
恩 谢谢 我再试试看
2010-06-30 11:16
o0慢节奏0o
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-3-28
收藏
得分:0 
回复 9楼 lintaoyn
弄好了 错误已修复 谢谢
2010-06-30 13:36
快速回复:排序有问题,说是访问冲突,麻烦大家看下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048238 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved