C语言课设学生信息管理系统.docx

上传人:b****5 文档编号:5040180 上传时间:2022-12-12 格式:DOCX 页数:15 大小:60.07KB
下载 相关 举报
C语言课设学生信息管理系统.docx_第1页
第1页 / 共15页
C语言课设学生信息管理系统.docx_第2页
第2页 / 共15页
C语言课设学生信息管理系统.docx_第3页
第3页 / 共15页
C语言课设学生信息管理系统.docx_第4页
第4页 / 共15页
C语言课设学生信息管理系统.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

C语言课设学生信息管理系统.docx

《C语言课设学生信息管理系统.docx》由会员分享,可在线阅读,更多相关《C语言课设学生信息管理系统.docx(15页珍藏版)》请在冰豆网上搜索。

C语言课设学生信息管理系统.docx

C语言课设学生信息管理系统

全局变量

structstud

{charname[20];

longnum;

intage;

charsex;

intscore[3];

chartele[12];

structstud*next;}

子程序

1.creat()函数

功能:

创建链表,提示输入学生信息,储存到链表中,录入完成后输入y继续,输入n停止,返回主菜单

2.display()函数

功能:

显示当前已经存入链表的信息

3.dele()函数

功能:

删除链表中学生信息,可按姓名或学号删除

4.add()函数

功能:

按学号插入学生信息

5.modify()函数

功能:

修改链表中学生信息

6.search()函数

功能:

查找学生信息,可按学号或姓名查找

7.sort()函数

功能:

对信息进行排序,可实现分别对三门成绩排序

8.save()函数

功能:

将链表中的数据保存到指定文件

9.load()函数

功能:

将指定文件中已有的数据读入链表

源程序

#include

#include

#include

#include

structstud

{charname[20];

longnum;

intage;

charsex;

intscore[3];

chartele[12];

structstud*next;}

main()

{structstud*head;

structstud*creat(void);

voiddisplay(structstud*head);

structstud*dele(structstud*head);

structstud*add(structstud*head);

structstud*modify(structstud*head);

voidsearch(structstud*head);

voidsave(structstud*head);

structstud*sort(structstud*head);

voidsave(structstud*head);

structstud*load();

charch;

head=NULL;

for(;;)

{clrscr();/*清屏函数*/

printf(“\n\n\t\tWelcometostudentinformationmanagementsystem”);printf(“\n\n\t**************************************************************”);printf(“\n\t\t\t1:

Entertheinformation”);

printf(“\n\t\t\t2:

Listtheinformation”);

printf(“\n\t\t\t3:

Deletetheinformation”);

printf(“\n\t\t\t4:

Addtheinformation”);

printf(“\n\t\t\t5:

Modifytheinformation”);

printf(“\n\t\t\t6:

Searchtheinformation”);

printf(“\n\t\t\t7:

Sorttheinformation”);

printf(“\n\t\t\t8:

Savetheinformation”);

printf(“\n\t\t\t9:

Loadtheinformation”);

printf(“\n\t\t\t0:

Exit“);

printf(“\n\t\t\tEnteryourchoice:

”);

fflush(stdin);

ch=getchar();

getchar();

switch(ch)

{

case‘1’:

head=creat();

break;

case‘2’:

display(head);

system(“pause”);

break;

case‘3’:

head=dele(head);

system(“pause”);

break;

case‘4’:

head=add(head);

system(“pause”);

break;

case‘5’:

head=modify(head);

system(“pause”);

break;

case‘6’:

search(head);

system(“pause”);

break;

case‘7’:

head=sort(head);

system(“pause”);

break;

case‘8’:

save(head);

system(“pause”);

break;

case‘9’:

head=load();

break;

case‘0’:

return;

break;

default:

clrscr();

printf(“\n\tError!

Pleasecheckyourinput\n\n”);

system(“pause”);

}}

}

structstud*creat(void)/*链表的创建*/

{structstud*head,*p1;

charch;

clrscr();

head=NULL;

p1=(structstud*)malloc(sizeof(structstud));

printf(“\tentername:

”);

gets(p1->name);printf(“\tenternumber:

”);

scanf(“%ld”,&p1->num);

printf(“\tenterage:

”);

scanf(“%d”,&p1->age);

printf(“\tentersex:

”);

fflush(stdin);

scanf(“%c”,&p1->sex);

printf(“\tenterMathscore:

”);

scanf(“%d”,&p1->score[0]);

printf(“\tenterEnglishscore:

”);

scanf(“%d”,&p1->score[1]);

printf(“\tenterCscore:

”);

scanf(“%d”,&p1->score[2]);

printf(“\tentertelephonenumber:

”);

fflush(stdin);gets(p1->tele);

head=p1;p1->next=NULL;

do{printf(“\n\tDOYOUWANTTOCONTINUE?

YorN?

”);

printf(“\n\tEnteryourchoise:

”);

fflush(stdin);ch=getchar();clrscr();if(ch==’y’||ch==’Y’)

head=add(head);

elseif(ch!

=’N’&&ch!

=’n’)

{printf(“\n\tError!

Pleasecheckyourinput”);

ch=’y’;}

}while(ch==’y’||ch==’Y’);

return(head);}

structstud*dele(structstud*head)/*链表的删除*/

{structstud*p1,*p2;

intchoose;

longdelnum;

charname[20];

clrscr();

printf(“\n\t\tChoosethewayyouwant”);

printf(“\n\t1:

Accordingtoname\n“);

printf(“\n\t2:

Accordingtonum\n”);

printf(“\n\tEnteryourchoice:

”);

scanf(“%d”,&choose);

fflush(stdin);

if(choose==1)

{printf(“\n\tEnterthename:

”);

gets(name);if(head==NULL){printf(“\t\nNoinformation!

\n”);return(head);}p1=head;while(strcmp(name,p1->name)!

=0&&p1->next!

=NULL)

{p2=p1;p1=p1->next;}

if(strcmp(name,p1->name)==0)

{if(p1==head)head=p1->next;

elsep2->next=p1->next;

printf(“\tDeleteSuccessed!

\n\n”);

}

elseprintf(“\tNotbeenfind!

\n\n”);

return(head);}

elseif(choose==2)

{printf(“\n\tEnterthenumber:

”);

scanf(“%ld”,&delnum);

if(head==NULL){printf(“\nNoinformation!

\n”);return(head);}p1=head;while(delnum!

=p1->num&&p1->next!

=NULL)

{p2=p1;p1=p1->next;}

if(delnum==p1->num)

{if(p1==head)head=p1->next;

elsep2->next=p1->next;

printf(“\tDeleteSuccessed!

\n\n”);

}

elseprintf(“\tNotbeenfind!

\n”);

return(head);

}

else{printf(“\n\tError!

Pleasecheckyourinput\n\n”);

return(head);}

}

voiddisplay(structstud*head)

{structstud*p;

p=head;

clrscr();

if(head==NULL)

printf(“\n\tNoinformation\n\n”);

else{printf(“name\tnumber\tage\tsex\tMath\tEnglish\tC\ttelephonenumber\n”);

do

{

printf(“%s\t%ld\t%d\t%c\t%d\t%d\t%d\t%s\n”,p->name,p->num,p->age,p->sex,p->score[0],p->score[1],p->score[2],p->tele);

p=p->next;}

while(p!

=NULL);}

}

structstud*add(structstud*head)/*链表的插入*/

{structstud*p1,*p2,*p0;

p0=(structstud*)malloc(sizeof(structstud));

clrscr();

printf(“\n\t\tInputtheinformation:

”);

printf(“\n\t\tname:

”);

fflush(stdin);

gets(p0->name);

printf(“\t\tnumber:

”);

scanf(“%ld”,&p0->num);

printf(“\t\tage:

”);

scanf(“%d”,&p0->age);

printf(“\t\tsex:

”);

fflush(stdin);

scanf(“%c”,&p0->sex);

printf(“\t\tMathscore:

”);

scanf(“%d”,&p0->score[0]);

printf(“\t\tEnglishscore:

”);

scanf(“%d”,&p0->score[1]);

printf(“\t\tCscore:

”);

scanf(“%d”,&p0->score[2]);

printf(“\t\ttelephonenumber:

”);

fflush(stdin);

gets(p0->tele);

p1=head;

if(head==NULL)

{head=p0;p0->next=NULL;}

else

{while(p0->num>p1->num)

{p2=p1,

p1=p1->next;}

if(p0->num<=p1->num)

{if(head==p1)head=p0;

elsep2->next=p0;

p0->next=p1;}

else{p1->next=p0;p0->next=NULL;}}

return(head);

}

structstud*modify(structstud*head)/*链表的修改*/

{structstud*p1,*p2,*p0;

clrscr();

printf(“\n\tInputthestudent’sname:

”);

p0=(structstud*)malloc(sizeof(structstud));

fflush(stdin);

gets(p0->name);

if(head==NULL){printf(“\nNoinformation!

\n\n”);return(head);}p1=head;while(strcmp(p0->name,p1->name)!

=0&&p1->next!

=NULL)

{p2=p1;p1=p1->next;}

if(strcmp(p0->name,p1->name)==0)

{printf(“name\tnumber\tage\tsex\tMath\tEnglish\tC\ttelephonenumber\n”);

printf(“%s\t%ld\t%d\t%c\t%d\t%d\t%d\t%s\n”,p1->name,p1->num,p1->age,p1->sex,p1->score[0],p1->score[1],p1->score[2],p1->tele);

if(p1==head)head=p1->next;elsep2->next=p1->next;printf(“\tNewinformation:

number:

”);scanf(“%ld”,&p0->num);printf(“\t\t\tage:

”);scanf(“%d”,&p0->age);printf(“\t\t\tsex:

”);fflush(stdin);scanf(“%c”,&p0->sex);printf(“\t\t\tMathscore:

”);scanf(“%d”,&p1->score[0]);printf(“\t\t\tEnglishscore:

”);scanf(“%d”,&p1->score[1]);printf(“\t\t\tCscore:

”);scanf(“%d”,&p1->score[2]);printf(“\t\t\ttelephonenumber:

”);fflush(stdin);gets(p0->tele);p1=head;if(head==NULL)

{head=p0;p0->next=NULL;}

else

{while(p0->num>p1->num)

{p2=p1;

p1=p1->next;}

if(p0->num<=p1->num)

{if(head==p1)head=p0;

elsep2->next=p0;

p0->next=p1;}

else{p1->next=p0;p0->next=NULL;}}

printf(“ModifySuccessed!

\n\n”);}

elseprintf(“Notbeenfind!

\n\n”);

return(head);

}

voidsearch(structstud*head)/*查询链表*/

{structstud*p;

intchoose;

longnum;

charname[20];

clrscr();

printf(“\n\t\tChoosethewayyouwant”);

printf(“\n\t1:

Accordingtoname\n“);

printf(“\n\t2:

Accordingtonum\n”);

printf(“\n\tEnteryourchoice:

”);

scanf(“%d”,&choose);

fflush(stdin);

if(choose==1)

{printf(“\n\tenterthename:

”);

gets(name);

if(head==NULL){printf(“\t\nNoinformation!

\n\n”);}

else

{p=head;

while(strcmp(name,p->name)!

=0&&p->next!

=NULL)

{p=p->next;}

if(strcmp(name,p->name)==0)

{printf(“name\tnumber\tage\tsex\tMath\tEnglish\tC\ttelephonenumber\n”);

printf(“%s\t%ld\t%d\t%c\t%d\t%d\t%d\t%s\n”,p->name,p->num,p->age,p->sex,p->score[0],p->score[1],p->score[2],p->tele);

}

elseprintf(“Notbeenfind!

\n\n”);}}

elseif(choose==2)

{printf(“\n\tEnterthenumber:

”);

scanf(“%ld”,&num);

if(head==NULL){printf(“\nNoinformation!

\n”);}

else

{p=head;

while(num!

=p->num&&p->next!

=NULL)

{p=p->next;}

if(num==p->num)

{printf(“name\tnumber\tage\tsex\tMath\tEnglish\tC\ttelephonenumber\n”);

printf(“%s\t%ld\t%d\t%c\t%d\t%d\t%d\t%s\n”,p->name,p->num,p->age,p->sex,p->score[0],p->score[1],p->score[2],p->tele);

}

elseprintf(“\tNotbeenfind!

\n”);}}

elseprintf(“\n\tError!

Pleasecheckyourinput\n\n”);

}

structstud*sort(structstud*head)

{

structstud*first;

structstud*t;

structstud*p;

structstud*q;

intch;

clrscr();

printf(“\n\t\tChoosethewayyouwant”);

printf(“\n\t1:

AccordingtoMath:

\n”);

printf(“\n\t2:

AccordingtoEnglish\n”);

printf(“\n\t3:

AccordingtoC\n”);

printf(“\n\tEnteryourchoice:

”);

scanf(“%d”,&ch);

first=head->next;

head->next=NULL;

while(first!

=NULL)

{for(t=first,q=head;((q!

=NULL)&&(q->score[ch-1]>t->score[ch-1]));p=q,q=q->next);

first=first->next;

if(q==head)

head=t;

else

{p->next=t;}

t->next=q;

}

printf(“\n\t\tSuccess!

\n”);

returnhead;

}

voidsave(structstud*head)/*保存链表*/

{FILE*fp;

structstud*p;

charfilename[20];

printf(“\n\ninputthefilename:

“);

fflush(stdin);

gets(filename);

if((fp=fopen(filename,”w”))==NULL)

{printf(“Savefile%serror!

Typeitagain.\n\n”,filename);

exit(0);}

p=head;

while(p!

=NULL)

{fprintf(fp,”%s\t”,p->name);

fprintf(fp,”%ld\t”,p->num);

fprintf(fp,”%d\t”,p->age);

fprintf(fp,”%c\t”,p->sex);

fprintf(fp,”%d\t”,p->score[0]);

fprintf(fp,”%d\t”,p->score[1]);

fprintf(fp,”%d\t”,p->score[2]);

fprintf(fp,”%s\t\n”,p->tele);

p=p->next;

}

printf(“\n\t\tSuccess!

\n”);

fclose(fp);

}

structstud*load()/*链表的导入*/

{FILE*fp;

charfilename[20];

structstud*head,*p1,*p2;

printf(“\n\ninputthefilename:

“);

fflush(stdin);

gets(filename);

if((fp=fopen(filename,”r”))==NULL)

{printf(“Loadfile%serror!

Typeitagain.\n\n”,filename);

exit(0);}

if(!

feof(fp))

{head=(structstud*)malloc(sizeof(structstud));

fscanf(fp,”%s\t”,&head->name);

fscanf(fp,”%ld\t”,&head->num);

fscanf(fp,”%d\t”,&head->age);

fscanf(fp,”%c\t”,&head->sex);

fscanf(fp,”

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 军事

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1