谁帮我修改一下这段代码!winTC下编辑提示错误
在WIN tc下编译提示错误,不会修改!请高手帮忙/坐等~~~~#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
struct student
{int num;/*学号*/
char name[20];/*名字*/
char sex[6];/*性别*/
int foxscore;/*fox成绩*/
int cscore;/*C语言 */
int englishscore;/*英语成绩*/
float zong;/*总成绩*/
int mingci;/*名次 */
struct student *next;
};
int n=0;
struct student *begin()/*开辟一个存储空间*/
{
struct student *head;
head=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
{
printf("没有足够空间!\n");
}
head->next=NULL;
return(head);
}
struct student *input(struct student *head)/*输入函数 */
{int k=1;
struct student *student,*p1;
student=(struct student *)malloc(sizeof(struct student));
while(k)
{ printf("输入学生信息:\n");
n++;
printf("请输入学生学号:");
scanf("%d",&student->num);
printf("请输入学生姓名:");
scanf("%s",&student->name);
printf("请输入学生性别:");
scanf("%s",&student->sex);
printf("请输入学生fox成绩:\n");
scanf("%d",&student->foxscore);
printf("请输入学生c语言成绩:\n");
scanf("%d",&student->cscore);
printf("请输入学生英语成绩:\n");
scanf("%d",&student->englishscore);
/* printf("是否继续?是按1 否按0\n");
scanf("%d",&k);
p1=(struct student *)malloc(sizeof(struct student));
if(k!=0)
{
student->next=p1;
student=p1;
}
}
student->next=NULL;
return(head);
}*/
if(n==1) {student->next=NULL; head=student;}
else {student->next=head;head=student;}
printf("是否继续?是按1 否按0\n");
scanf("%d",&k);
p1=(struct student *)malloc(sizeof(struct student));
if(k!=0)
{
p1->next=student;
student=p1;
}
}
return(head);
}
struct student *revise(struct student *head)/* 修改函数 */
{ struct student *p1,*p2;int u,t;
printf("请输入要修改学生学号:");
scanf("%d",&u); p1=head;
while(p1->num!=u&&p1->next !=NULL )
{p2=p1;p1=p1->next;}
if(u==p1->num)
{
printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);/*printf("\n"); */
printf("性别: "); puts(p1->sex);/*printf("\n"); */
printf("fox成绩:%d\n",p1->foxscore);
printf("c语言成绩:%d\n",p1->cscore);
printf("英语成绩:%d\n",p1->englishscore);
}
printf("*******1.修改学号*****\n");
printf("*******2.修改姓名*****\n");
printf("*******3.修改性别*****\n");
printf("*******4.修改成绩*****\n");
printf(" please input choice(0-4):");
scanf("%d",&t);
switch(t)
{ case 1: {printf("请输入学生学号:");
scanf("%d",&p1->num);} break;
case 2: {printf("请输入学生姓名:");
scanf("%s",&p1->name);} break;
case 3: {printf("请输入学生性别:");
scanf("%s",&p1->sex);} break;
case 4: { printf("请输入学生fox成绩:\n");
scanf("%d",&p1->foxscore);
printf("请输入学生c语言成绩:\n");
scanf("%d",&p1->cscore);
printf("请输入学生英语成绩:\n");} break;
}
return(head);
}
void print(struct student *head)/* 输出函数 */
{struct student *p;
p=head;
do
{printf("学号:%d\n",p->num);
printf("姓名: "); puts(p->name);
printf("性别: "); puts(p->sex);
printf("fox成绩: %d\n",p->foxscore);
printf("c语言成绩: %d\n",p->cscore);
printf("英语成绩: %d\n",p->englishscore);
p->zong=(float)(p->foxscore+p->cscore+p->englishscore);
printf("总成绩: %.1f\n",p->zong);
printf("\n");
p=p->next; }while(p!=NULL);
}
void paiming(struct student *head)/* *****排名次***** */
{int i; struct student *p0,*p1,*p2;
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong<p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
/* ****************交换结点内容****************** */
else
{p2=p1;p1=p1->next;}
}
}
p1=head;
for(i=1;i<=n;i++)
{p1->mingci=i; p1=p1->next;
}
}
void chaxun(struct student *head)/* 查询函数*/
{
int t,nu,mc;char na[20];struct student *p1,*p2;
printf("*******1.按学号查询*****\n");
printf("*******2.按姓名查询*****\n");
printf("*******3.按名次查询*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(0-3):");
scanf("%d",&t);
switch(t)
{
case 1: {printf("请输入学生学号:");
scanf("%d",&nu);
if(head==NULL) printf("无数据\n");
p1=head;
while(nu!=p1->num&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(nu==p1->num)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
printf("\n");
}
else printf("学号%d 的学生未找到\n",nu);};break;
case 2: { printf("请输入学生姓名:");
scanf("%s",na);
if(head==NULL) {printf("无数据\n");}
p1=head;
while(strcmp(na,p1->name)!=0&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(strcmp(na,p1->name)==0)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
}
else printf("该学生未找到\n");} break;
case 3: {paiming(head);
printf("请输入学生名次:");
scanf("%d",&mc);
if(head==NULL) {printf("无数据\n");}
p1=head;
while(mc!=p1->mingci&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(mc==p1->mingci)
{printf("学号:%d\n",p1->num);
printf("姓名: "); puts(p1->name);
printf("性别: "); puts(p1->sex);
printf("fox成绩: %d\n",p1->foxscore);
printf("c语言成绩: %d\n",p1->cscore);
printf("英语成绩: %d\n",p1->englishscore);
}
else printf("名次%d 的学生未找到\n",mc);} break;
case 0:break;
}
}
struct student *shanchu(struct student *head)/* 删除函数 */
{
int t,nu,mc;char na[20];struct student *p1,*p2;
printf("*******1.按学号删除*****\n");
printf("*******2.按姓名删除*****\n");
printf("*******3.按名次删除*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(0-3):");
scanf("%d",&t);
switch(t)
{
case 1: {printf("请输入学学号:");
scanf("%d",&nu);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(nu!=p1->num&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(nu==p1->num)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("学号%d 的学生未找到\n",nu);} break;
case 2: { printf("请输入学生姓名:");
scanf("%s",na);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(strcmp(na,p1->name)!=0&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(strcmp(na,p1->name)==0)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("该学生未找到\n");} break;
case 3: { paiming(head);
printf("请输入学生名次:");
scanf("%d",&mc);
if(head==NULL) {printf("无数据\n");return NULL;}
p1=head;
while(mc!=p1->mingci&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(mc==p1->mingci)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
n=n-1;
free(p1);printf("已删除");
}
else printf("名次%d的学生未找到\n",mc);} break;
case 0:break;
}
return(head);}
struct student *paixu(struct student *head)/* 排序函数 */
{int i,s,t;struct student *p1,*p2,*p0;
printf("*******1.按学号排序*****\n");
printf("*******2.按姓名排序*****\n");
printf("*******3.按成绩排序*****\n");
printf("*******0.退出*********\n");
printf(" please input choice(1-3):");
scanf("%d",&t);
switch(t)
{
case 1:
{printf("********1.按学号升续*****\n");
printf("*******2.按学号降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->num>p1->num)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
/* ****************交换结点内容**************** */
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->num<p1->num)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
/* ****************交换结点内容****************** */
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 2:
{printf("*******1.按姓名升续*****\n");
printf("*******2.按姓名降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(strcmp(p1->name,p2->name)<0)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore; }
/* ****************交换结点内容****************** */
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(strcmp(p1->name,p2->name)>0)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
/* ****************交换结点内容****************** */
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 3:
{ printf("*******1.按成绩升续*****\n");
printf("*******2.按成绩降续*****\n");
scanf("%d",&s);
for(i=1;i<n;i++)
{
p2=head;p1=p2;
p0=(struct student *)malloc(sizeof(struct student));
if(s==1)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong>p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
/* ****************交换结点内容****************** */
else
{p2=p1;p1=p1->next;}
}
}
else if(s==2)
{while(p2->next!=NULL)
{ p1=p2->next;
if(p2->zong<p1->zong)
{p0->num=p2->num;strcpy(p0->name,p2->name);strcpy(p0->sex,p2->sex);
p0->zong=p2->zong;p0->mingci=p2->mingci;
p0->foxscore=p2->foxscore;p0->cscore=p2->cscore;p0->englishscore=p2->englishscore;
p2->num=p1->num;strcpy(p2->name,p1->name);strcpy(p2->sex,p1->sex);
p2->zong=p1->zong;p2->mingci=p1->mingci;
p2->foxscore=p1->foxscore;p2->cscore=p1->cscore;p2->englishscore=p1->englishscore;
p1->num=p0->num;strcpy(p1->name,p0->name);strcpy(p1->sex,p0->sex);
p1->zong=p0->zong;p1->mingci=p0->mingci;
p1->foxscore=p0->foxscore;p1->cscore=p0->cscore;p1->englishscore=p0->englishscore;}
/* ****************交换结点内容****************** */
else
{p2=p1;p1=p1->next;}
}
}
}
}
break;
case 0:break;
}
print(head);
return(head);}
/* *********操作文件******* */
void save(struct student *l)
{struct student *y;
FILE *fp;
char ch[20];
cout<<"请输入文件名!"<<endl;
scanf("%s",ch);
if((fp=fopen(ch,"wb+"))==NULL)
{cout<<"打开失败!"<<endl;
exit(0);}
for(y=l;y!=NULL;y=y->next)
fwrite(y,sizeof(struct student),1,fp);
fclose(fp);
cout<<"保存成功!"<<endl;
}
void readfl()
{struct student *k,st;
char ch[20];
FILE *fp;
k=&st;
cout<<"请输入您要打开的文件名!"<<endl;
scanf("%s",ch);
if((fp=fopen(ch,"rb+"))==NULL)
{cout<<"打开失败!"<<endl;
exit(0);}
fread(&st,sizeof(struct student),1,fp);
while(!feof(fp))
{printf("学号:%d\n",k->num);
printf("姓名: "); puts(k->name);/* printf("\n");*/
printf("性别: "); puts(k->sex);/* printf("\n"); */
printf("fox成绩: %d\n",k->foxscore);
printf("c语言成绩: %d\n",k->cscore);
printf("英语成绩: %d\n",k->englishscore);
k->zong=(float)(k->foxscore+k->cscore+k->englishscore);
printf("总成绩: %.1f\n",k->zong);
fread(&st,sizeof(struct student),1,fp);
}
fclose(fp);
}
void main()
{int c; struct student *head;
head=begin();
printf("\n\t\t***********学生成绩管理系统***********\n\n");
while(1)
{printf("\n\t\t****************菜单*****************\n\n");
printf( "\t\t*\t1.建立信息 *\n");
printf( "\t\t*\t2.信息修改 *\n");
printf("\t\t*\t3.信息显示 *\n");
printf("\t\t*\t4.信息查询 *\n");
printf("\t\t*\t5.信息删除 *\n");
printf("\t\t*\t6.按学生信息排序 *\n");
printf("\t\t*\t7.信息保存 *\n");
printf("\t\t*\t8.信息输出 *\n");
printf( "\t\t*\t0.退出 *\n");
printf("\t\t*************************************\n");
do {
printf("\n\t\t please input choice(0-9):");
scanf("%d",&c);
}while(c<0||c>8);
/* return c;*/
switch (c)
{ case 1:head=input(head);break;
case 2:if(n==0) printf("请先输入信息");
else head=revise(head);break;
case 3:if(n==0) printf("请先输入信息");
else print(head); break;
case 4:chaxun(head);break;
case 5:head=shanchu(head);break;
case 6:if(n==0) printf("请先输入信息");
else head=paixu(head);break;
case 7:save(head);break;
case 8:if(n==0) printf("请先输入信息");
else readfl();break;
case 0:exit(0);break;}
}
}