关于C语言课题设计(学生信息管理系统)

功能要求及说明1数据录入功能2查询功能3删除功能4排序功能
2024-11-25 19:48:40
推荐回答(2个)
回答1:

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#include"conio.h"
typedef struct Student
{char name[20];
char num[20];
int score;
Student *next;
}student;
student *creat()
{student *head;student *p,*s;int flag=1;
head=(student*)malloc(sizeof(student));p=(student*)malloc(sizeof(student));
head->next=p;
if(!p){printf("失败");return 0;}

printf("输入姓名:");gets(p->name);
printf("输入学号:");scanf("%s",p->num);
printf("输入成绩:");scanf("%d",&p->score);
while(flag)
{s=(student*)malloc(sizeof(student));
getchar();
printf("输入姓名:(输入0退出):");gets(s->name);
if(!strcmp(s->name,"0")){flag=0;break;}
printf("输入学号:");scanf("%s",s->num);
printf("输入成绩:");scanf("%d",&s->score);
p->next=s;
p=s;
}
p->next=NULL;
return head;
}
void listprint(student *head)
{student *p;
p=head->next;
while(p)
{printf("姓名:%s\n学号:%s\n成绩:%d\n",p->name,p->num,p->score);
p=p->next;
}
}
void listfind(student *head,char str[])
{student *p;p=head->next;
if(p)
{
while(p&&(strcmp(p->name,str)&&strcmp(p->num ,str)))
p=p->next;

if(p){ printf("姓名:%s\n学号:%s\n成绩:%d\n",p->name,p->num,p->score);}
else printf("没有该学生信息!\n");
}
}
void listadd(student *head)
{student *p,*s;int flag=1;
p=head->next;
while(p->next!=NULL)p=p->next;
while(flag)
{s=(student*)malloc(sizeof(student));

printf("输入姓名:(输入0退出):");gets(s->name);
if(!strcmp(s->name,"0")){ flag=0;break;}
printf("输入学号:");scanf("%s",s->num);
printf("输入成绩:");scanf("%d",&s->score);
p->next=s;
p=s;
getchar();
}
p->next=NULL;
}
void listdel(student *head,char str[])
{student *p1,*p2;p2=head;
p1=head->next;
while(p1&&(strcmp(p1->name,str)&&strcmp(p1->num ,str)))
{p2=p1;p1=p1->next;}
if(!p1)printf("\n\n\n\n\t 没有该学生的信息\n");
else {p2->next=p1->next;printf("\n\n\n\n\n\t\t\t\t 删除成功!\n\n");free(p1);}
}
void listsort(student *head)
{student *p1,*p2,*p3,*p4,*temp;temp=(student *)malloc(sizeof(student));
p1=p2=head->next;
for(;p1!=NULL;p1=p1->next)
{p2=p3=p1;p4=p3;
for(;p3!=NULL;p3=p3->next)
{
if(p3->score>p4->score){p4=p3;}
}strcpy(temp->name,p2->name);strcpy(temp->num,p2->num);temp->score=p2->score;
strcpy(p2->name,p4->name);strcpy(p2->num,p4->num);p2->score=p4->score;
strcpy(p4->name,temp->name);strcpy(p4->num,temp->num);p4->score=temp->score;}}

void menu()
{printf("\n\n\n\n\t\t\t菜单\n\t\t\t\n\t\t\t请选择\n\t\t\t********************\n\t\t\t*1创建资料\n\t\t\t*2查找\n\t\t\t*3显示全部\n\t\t\t*4添加\n\t\t\t*5删除\n\t\t\t*6排名\n\t\t\t*7退出\n\t\t\t********************\n");
}

int main()
{student *head;char str[20],ch; int count=0;

while(1)
{menu();ch=getch();
system("cls");
if(ch!='1'&&ch!='7'&&count==0){printf("\n\n\n\n\n\n\t\t\t 你还没有创建资料\n");printf("\n\t\t 按任意键回主菜单\n");getch();system("cls");continue;}
else count=1;
switch(ch)
{case '1':head=creat();break;
case '2':printf("输入要查找的姓名或学号:");gets(str);listfind(head,str);break;
case '3':listprint(head);break;
case '4':listadd(head);break;
case '5':printf("输入要删除的姓名或学号:");gets(str);listdel(head,str);break;
case '6':listsort(head);listprint(head);break;
case '7':printf("\n\n\n\n\n\n\t\t\t 谢谢使用\n\n\n\n\n");getchar();return 0;
}printf("\n\t\t 按任意键回主菜单\n");getch();system("cls");
}

}

回答2:

什么时候要,我这两天可以免费为你写一个!