澳新航线:急!!!!c语言学生管理系统

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/26 21:55:23
成绩的添加,删除等..

struct student
{
char num[10];
char name[20];
char sex[4];
int ave;
int totle;
int cgrade;
int mgrade;
int egrade;
};
void Add(link l)
{
Node *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next;
while(1)
{
printf("input your numbers('0' of back:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{if(strcmp(s->data.num,num)==0)
{printf("=====>error:the number '%s' has inputed,if chang ,please '4' !\n",num);
printstart();
printc();
printe(s);
printstart();
printf("\n");
return;
}
s=s->next;
}
p=(Node *)malloc(sizeof(Node));
strcpy(p->data.num,num);
printf("please input your name:");
scanf("%s",p->date.name);
printf("please input your sex:");
scanf("%s",p->data.sex);
printf("please input your C grade:");
scanf("%d",&p->data.cgrade);
printf("please input your month grade:");
scanf("%d",&p->data.mgrade);
printf("please input your english grade:");
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle / 3;
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;
}
}

void Del(Link l)
{int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{printf("\n=====>no message will be dellted!\n");
return;}
printf("\n=====>1:input the number\n");
scanf("%d",&sel);
if(sel==1)
{ printf(" input the number you want to del:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{ r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>notice: successed to del!\n");
shoudsave=1;}
else Nofind();
}
else Wrong();
}
void Qur(Link l)
{ int sel;
char findmess[20];
Node *p;
if(!l->next)
{ printf("\n=====>error:no message can be qur!\n");
return;}
printf("\n=====>1:input the number\n");
scanf("%d",&sel);
if(sel==1)
{ printf("input the number:\n");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{ printf("\t\t\t\tThe result\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else
Wrong();
}

后面还有

希望大家给小弟一点指点
不知道程序错在哪里
还有,怎么打开文件,文件是什么格式(fp=fopen("C:\\student","rb");)
(是学生管理系统)
谢谢各位了

前面的是乱码,后面的才有翻译

printf(" 菜 单\n");
printf(" ┌——————————————————┐\n");
printf(" │ 0.增加学生信息 │\n");
printf(" │ 1. 删除学生信息 │\n");
printf(" │ 2. 插入学生信息 │\n");
printf(" │ 3. 查找学生信息 │\n");
printf(" │ 4. 修改学生 │\n");
printf(" │ 5. 显示学生 │\n");
printf(" │ 6. 保存学生 │\n");
printf(" └——————————————————┘\n");
printf(" 选择代码(1,2,3,4,5,6");
scanf("%d",&sel);
return sel;
}

你的算法有严重问题,看来基础不太牢。

前面的是乱码,后面的才有翻译

printf(" 菜 单\n");
printf(" ┌——————————————————┐\n");
printf(" │ 0.增加学生信息 │\n");
printf(" │ 1. 删除学生信息 │\n");
printf(" │ 2. 插入学生信息 │\n");
printf(" │ 3. 查找学生信息 │\n");
printf(" │ 4. 修改学生 │\n");
printf(" │ 5. 显示学生 │\n");
printf(" │ 6. 保存学生 │\n");
printf(" └——————————————————┘\n");
printf(" 选择代码(1,2,3,4,5,6");
scanf("%d",&sel);
return sel;
}

void Modify(Link l)
{ Node *p;
char findmess[20];
if(!l->next)
{ printf("\n=====>error:no message can be change!\n");
return;}
printf("input the number:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{ printf("input the new number(old is %s):",p->data.num);
scanf("%s",p->data.num);
printf("input the new name (old is %s):",p->data.name);
scanf("%s",p->data.name);
printf("input the new sex (old is %s):",p->data.sex);
scanf("%s",p->data.sex);
printf("input the new C grade (old is %d):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
printf("input the new month grade (old is %d):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
printf("input the new english grade (old is %d):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>notice: successed to change!\n");
shoudsave=1;
}
else
Nofind();
}
void Disp (Link l)
{ int count=0;
Node *p;
p=l->next;
if(!p)
{printf("\n=====>error:no message !\n");
return;
}
printf("\t\t\t\tresult\n");
printstart();
printc();
printf("\n");
while(p)
{printe(p);
p=p->next;}
printstart();
printf("\n");
}
void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{printf("\n=====>notice:opening the file found error!\n");
exit(1);}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{ p=p->next;count++; }
else
{flag=0;break;}
}
if(flag)
{ printf("\n=====>cotice :Saved success!\n",count);
shoudsave=0; }
fclose(fp);
}
void main()
{ Link l;
FILE *fp;
int sel;
char ch;
char jian;
int count=0;
Node *p,*r;
printf("\t\t\t\tThe student manage system\n\t\t\t\t------\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;
fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>The file not found, New or not?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y') fopen()
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>notice:The file has opened,loading......\n");
while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp))
{
p->next=NULL;
r->next=p;
r=p;
count++;
}
}
fclose(fp);
printf("\n=====>notice: successed to load! \n");
while(1)
{
menu();
printf("please chose.");
scanf("%d",&sel);
if(sel==0)
{if(shoudsave==1)
{
printf("\n=====>notice:The message have been changed,save or not?(y/n)\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>notice:EXIT,BYE!\n");
break;
}
switch(sel)
{
case 1:Add(l);break;
case 2:Del(l);break;
case 3:Qur(l);break;
case 4:Modify(l);break;
case 5:Disp(l);break;
case 6:Save(l);break;
default: Wrong();getchar();break;
}
}
}
int menu()
{
int sel;
printf(" 菜 单\n");
printf(" ┌——————————————————┐\n");
printf(" │ 0.增加学生信息 │\n");
printf(" │ 1. 删除学生信息 │\n");
printf(" │ 2. 插入学生信息 │\n");
printf(" │ 3. 查找学生信息 │\n");
printf(" │ 4. 修改学生 │\n");
printf(" │ 5. 显示学生 │\n");
printf(" │ 6. 保存学生 │\n");
printf(" └——————————————————┘\n");
printf(" 选择代码(1,2,3,4,5,6");
scanf("%d",&sel);
return sel;
}
不知??

void Modify(Link l)
{ Node *p;
char findmess[20];
if(!l->next)
{ printf("\n=====>error:no message can be change!\n");
return;}
printf("input the number:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{ printf("input the new number(old is %s):",p->data.num);
scanf("%s",p->data.num);
printf("input the new name (old is %s):",p->data.name);
scanf("%s",p->data.name);
printf("input the new sex (old is %s):",p->data.sex);
scanf("%s",p->data.sex);
printf("input the new C grade (old is %d):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
printf("input the new month grade (old is %d):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
printf("input the new english grade (old is %d):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>notice: successed to change!\n");
shoudsave=1;
}
else
Nofind();
}
void Disp (Link l)
{ int count=0;
Node *p;
p=l->next;
if(!p)
{printf("\n=====>error:no message !\n");
return;
}
printf("\t\t\t\tresult\n");
printstart();
printc();
printf("\n");
while(p)
{printe(p);
p=p->next;}
printstart();
printf("\n");
}
void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{printf("\n=====>notice:opening the file found error!\n");
exit(1);}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{ p=p->next;count++; }
else
{flag=0;break;}
}
if(flag)
{ printf("\n=====>cotice :Saved success!\n",count);
shoudsave=0; }
fclose(fp);
}
void main()
{ Link l;
FILE *fp;
int sel;
char ch;
char jian;
int count=0;
Node *p,*r;
printf("\t\t\t\tThe student manage system\n\t\t\t\t------\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;
fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>The file not found, New or not?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y') fopen()
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>notice:The file has opened,loading......\n");
while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp))
{
p->next=NULL;
r->next=p;
r=p;
count++;
}
}
fclose(fp);
printf("\n=====>notice: successed to load! \n");
while(1)
{
menu();
printf("please chose.");
scanf("%d",&sel);
if(sel==0)
{if(shoudsave==1)
{
printf("\n=====>notice:The message have been changed,save or not?(y/n)\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>notice:EXIT,BYE!\n");
break;
}
switch(sel)
{
case 1:Add(l);break;
case 2:Del(l);break;
case 3:Qur(l);break;
case 4:Modify(l);break;
case 5:Disp(l);break;
case 6:Save(l);break;
default: Wrong();getchar();break;
}
}
}
int menu()
{
int sel;
printf(" 菜 单\n");
printf(" ┌——————————————————┐\n");
printf(" │ 0.增加学生信息 │\n");
printf(" │ 1. 删除学生信息 │\n");
printf(" │ 2. 插入学生信息 │\n");
printf(" │ 3. 查找学生信息 │\n");
printf(" │ 4. 修改学生 │\n");
printf(" │ 5. 显示学生 │\n");
printf(" │ 6. 保存学生 │\n");
printf(" └——————————————————┘\n");
printf(" 选择代码(1,2,3,4,5,6");
scanf("%d",&sel);
return sel;
}

你来错地方了
你应该去电脑网络区