题目:学生成绩管理是学校教务管理的重要组成部分,其处理信息量很大,本实验是对学生的成绩管理作一个简单的模拟,用菜单选择操作方式完成下列功能:
(1)学生成绩;
(2)查询学生成绩;
(3)插入学生成绩;
(4)删除学生成绩。
我的程序:(能运行,但是功能不全,希望高手指点!)
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define ERROR 0
#define OK 1
typedef struct Node
{
int id,score;
char name[21];
struct Node *next;
}students,*Linklist;
Linklist creat_new(){ //建立单链表
Linklist L=NULL;
students *s;
int id,score;
char name[21];
int flag=0;
printf("Please input the ID:\n",id);
scanf("%d",&id);
while (id!=flag)
{
s=new students;
s->id=id;
printf("Please input the NAME:\n",name);
scanf("%s",&name);
strcpy(s->name,name);
printf("Please input the SCORE:\n",score);
scanf("%d",&score);
printf("Please input the ID(Enter 0 to end):\n",id);
scanf("%d",&id);
s->score=score;
s->next=L;
L=s;
}
return L;
}
students *Get_Linklist(Linklist L,int id){ //以序号查找
students *s;
int j=1;
s=L;
while(s->next!=NULL&&j<=id)
{ s=s->next;
j++;
}
if(j==id)
return s;
else
return NULL;
}
int Insert_Linklist(Linklist L,int pos,int id,char name[],int score){
students *p,*s;
p=Get_Linklist(L,pos-1);
if(p==NULL)
{ printf("The position was wrong!\n");
return ERROR;
}
else
{ s=new students;
s->id=id;
strcpy(s->name,name);
s->score=score;
s->next=p->next;
p->next=s;
return OK;
}
}
int Del_Linklist (Linklist L,int pos){ //删除数据
students *p,*s;
p=Get_Linklist(L,pos-1);
if(p==NULL)
{ printf("The position don't exit!\n");
return ERROR;
}
else
if(p->next==NULL)
{ printf("The position don't exit!\n");
return ERROR;
}
else
{ s=p->next;
p->next=s->next;
delete s;
return OK;
}
}
main()
{
int t=1;
int pos,i;
Linklist L;
students *s;
int id,score;
char chocie,name[21];
while(t)
{ printf("\n");
printf("**********************************\n");
printf("* Welcome to the manage system! *\n");
printf("* Creat--------1 *\n");
printf("* Find---------2 *\n");
printf("* Insert-------3 *\n");
printf("* Delete-------4 *\n");
printf("* Quit---------5 *\n");
printf("**********************************\n");
printf("Please enter your chocie:\n");
chocie=getchar();
if(chocie=='1')creat_new();
else
if(chocie=='2')
{ printf("Please input the ID:\n");
scanf("%d",&i);
if(i==s->id)
{ Get_Linklist(L,i);
printf("%d %-5s %-5d\n",s->id,s->name,s->score) ; }
else printf("ERROR!\n");
}
else
if(chocie=='3')
{ printf("Please input the POSITION:\n");
scanf("%d",&pos);
printf("Please input the ID:\n");
scanf("%d",&id);
printf("Please input the NAME:\n");
scanf("%s",name);
printf("Please input the SCORE:\n");
scanf("%d",&score);
Insert_Linklist(L,pos,id,name,score);
}
else
if(chocie=='4')
{ printf("Please input the ID:\n");
scanf("%d",&pos);
if(pos==s->id)
Del_Linklist(L,pos);
else printf("ERROR!\n");
}
else
if(chocie=='5')
{
t=0;
}
}
}
----------------解决方案--------------------------------------------------------