600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > C语言学生信息管理系统源代码

C语言学生信息管理系统源代码

时间:2020-02-06 16:19:44

相关推荐

C语言学生信息管理系统源代码

相关文章推荐:

1、C语言学生成绩管理系统源代码★★★★★

2、C语言学籍管理系统源代码★★

3、C语言学生成绩管理系统设计 《C语言程序设计》实训报告★★★

4、职工信息管理系统C++代码★★★

扫描上方二维码,回复999直接获取作者之前收藏的学习资源,谢谢网友们的分享。

更多管理系统更新中,请注意关注!

大学C语言实训课学习到的一段源代码,C语言学生信息管理系统。

#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<string.h>struct stu_inf//学生信息结构体定义{int age,year,month;long int number;char name[10],sex[4],tel[15],email[30],address[50];struct stu_inf *next;};#define LEN sizeof(struct stu_inf)int STU_SUM=0;//学生总数同时写入文件再次读取可防止读取空文本出现乱码的情况。int FLAG=0;//判断是否对学生信息进行了改动struct stu_inf *Stu_Create(struct stu_inf *head);//学生信息录入struct stu_inf *Stu_Delete(struct stu_inf *head);//学生信息删除struct stu_inf *Stu_Correct(struct stu_inf *head);//学生信息修改struct stu_inf *Stu_Search_Number(struct stu_inf *head,int number);//按学号查询学生信息struct stu_inf *Stu_Search_Name(struct stu_inf *head,char *name);//按姓名查询学生信息struct stu_inf *Stu_Insert(struct stu_inf *head,struct stu_inf *stu);//学生信息的插入void Stu_Print(struct stu_inf *head);//学生信息的输出void Stu_Search(struct stu_inf *head);//选择按何种方式查询学生信息void Write_Data(struct stu_inf *head);//学生信息写入到文件struct stu_inf *Read_Data();//学生信息读入到文件void main(){char choice,choice2;struct stu_inf *head=NULL;head=Read_Data();do{printf("\n\t\t------------------\n");printf("\t\t学生信息管理系统\n");printf("\t\t-*-*-*-*-*-*-*-*-*\n");printf("\t\t(1)---录入学生信息\n");printf("\t\t(2)---浏览学生信息\n");printf("\t\t(3)---查询学生信息\n");printf("\t\t(4)---删除学生信息\n");printf("\t\t(5)---修改学生信息\n");printf("\t\t(0)---退出系统\n");printf("\t\t-*-*-*-*-*-*-*-*-*\n");printf("\t\t请输入您的选择:");choice=getche();putchar('\n');switch(choice){case '1':head=Stu_Create(head);break;case '2':Stu_Print(head);break;case '3':Stu_Search(head);break;case '4':head=Stu_Delete(head);break;case '5':Stu_Correct(head);break;case '0':if(FLAG==1){printf("\n是否将改动保存到“学生信息.txt”?(y/n)\n");do{choice2=getche();switch(choice2){case 'y':Write_Data(head);break;case 'n':break;}}while(choice2!='n'&&choice2!='y');}break;default:printf("\n无效的选项。\n");break;}printf("\n按任意键继续...");getch();putchar('\n');}while(choice!='0');exit(0);}stu_inf *Stu_Create(struct stu_inf *head)//学生信息录入{struct stu_inf *p;p=(struct stu_inf *)malloc(LEN);printf("\n请输入学号:");scanf("%d",&p->number);printf("请输入姓名:");scanf("%s",p->name);printf("请输入年龄:");scanf("%d",&p->age);printf("请输入性别:");scanf("%s",p->sex);printf("请输入出生年月(年月之间用空格隔开):");scanf("%d%d",&p->year,&p->month);printf("请输入地址:");scanf("%s",p->address);printf("请输入电话号码:");scanf("%s",p->tel);printf("请输入E-mail:");scanf("%s",p->email);p->next=NULL;head=Stu_Insert(head,p);STU_SUM++;FLAG=1;printf("\n该学生的信息为:\n"); printf("-----------------------------------------------------------\n"); printf("学号\t姓名\t年龄\t性别\t出生年月\t\t地址\t电话\tE-mail\n"); printf("%d\t%s\t%d\t%s\t%d %d\t%s\t\t%s\t%s\n",p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email);return head;}struct stu_inf *Stu_Insert(struct stu_inf *head,struct stu_inf *stu)//学生信息插入{struct stu_inf *phead=head,*pstu=stu,*previous;if(head==NULL)head=stu;else{while(pstu->number > phead->number && phead->next != NULL)previous=phead,phead=phead->next;if(pstu->number <= phead->number){if(phead==head)head=pstu;elseprevious->next=pstu;pstu->next=phead;}elsephead->next=pstu;}return head;}void Stu_Search(struct stu_inf *head)//选择按何种方式查询学生信息{if(head==NULL){printf("\n无学生信息。\n\n");return ;}int number;char choice;char *name=(char *)calloc(15,sizeof(char));do{printf("\n\n\t学生信息查询\n");printf("------------------------------\n");printf("\t按学号查询 请按1\n");printf("\t按姓名查询 请按2\n");printf("\t取消 请按0\n");printf("------------------------------\n");printf("请输入您的选择:");choice=getche();putchar('\n');switch(choice){case '0':return;case '1':printf("\n请输入学号:");scanf("%d",&number);Stu_Search_Number(head,number);break;case '2':printf("\n请输入姓名:");scanf("%s",name);Stu_Search_Name(head,name);break;default:printf("\n无效的选项。\n");break;}printf("\n按任意键继续...");getch();putchar('\n');}while(1);}struct stu_inf *Stu_Search_Number(struct stu_inf *head,int number)//按学号查询学生信息{struct stu_inf *p=head;if(head==NULL)printf("\n无学生信息。\n\n");else{while(p->number != number && p->next != NULL)p=p->next;if(p->number==number){printf("\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t电话\tE-mail\n");printf("%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n",p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email);}elseprintf("\n无该学生的记录。\n\n");}return p;}struct stu_inf *Stu_Search_Name(struct stu_inf *head,char *name)//按姓名查询学生信息{struct stu_inf *p=head;if(head==NULL)printf("\n无学生信息。\n\n");else{while(strcmp(p->name,name) != 0 && p->next != NULL)p=p->next;if(strcmp(p->name,name)==0){printf("\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t电话\tE-mail\n");printf("%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n",p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email);}elseprintf("\n无该学生的记录。\n\n");}return p;}void Stu_Print(struct stu_inf *head)//学生信息的输出{struct stu_inf *p=head;if(head==NULL)printf("\n无学生信息。\n\n");else{printf("\n学生总数:%d\n",STU_SUM);printf("\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t电话\tE-mail\n");while(p!=NULL){printf("%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n",p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email);p=p->next;}}}struct stu_inf *Stu_Delete(struct stu_inf *head)//学生信息删除{struct stu_inf *phead=head,*previous;int number;if(head==NULL){printf("\n无学生信息。\n\n");return NULL;}printf("\n请输入要删除的学生的学号:");scanf("%d",&number);while(phead->number != number && phead->next != NULL)previous=phead,phead=phead->next;if(phead->number==number){if(phead==head)head=phead->next;elseprevious->next=phead->next;printf("\n删除成功。\n\n");STU_SUM--;FLAG=1;}elseprintf("\n无该学生的信息。\n\n");return head;}struct stu_inf *Stu_Correct(struct stu_inf *head)//学生信息修改{struct stu_inf *phead=head;int number;char choice;if(head==NULL){printf("\n无学生信息。\n\n");return NULL;}else{printf("\n请输入要修改的学生的学号:");scanf("%d",&number);while(phead->number != number && phead->next != NULL)phead=phead->next;if(phead->number==number){printf("\n该学生的信息:\n");printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");printf("\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t电话\tE-mail\n");printf("%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n",phead->number,phead->name,phead->age,phead->sex,phead->year,phead->month,phead->address,phead->tel,phead->email);printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n");do{printf("---------------------\n");printf("修改姓名请按1\n");printf("修改年龄请按2\n");printf("修改性别请按3\n");printf("修改出生年月 请按4\n");printf("修改地址请按5\n");printf("修改电话号码 请按6\n");printf("修改E-mail 请按7\n");printf("取消请按0\n");printf("---------------------\n");printf("请输入您的选择:");choice=getche();putchar('\n');switch(choice){case '0':return head;case '1':printf("\n请输入新姓名:");scanf("%s",phead->name);FLAG=1;break;case '2':printf("\n请输入新年龄:");scanf("%d",&phead->age);FLAG=1;break;case '3':printf("\n请输入新性别:");scanf("%s",phead->sex);FLAG=1;break;case '4':printf("\n请输入新的出生年月(年月之间用空格隔开):");scanf("%d%d",&phead->year,&phead->month);FLAG=1;break;case '5':printf("\n请输入新的地址:");scanf("%s",phead->address);FLAG=1;break;case '6':printf("\n请输入新的电话号码:");scanf("%s",phead->tel);FLAG=1;break;case '7':printf("\n请输入新的E-mail:");scanf("%s",phead->email);FLAG=1;break;default:printf("\n无效的选项。\n\n");break;}printf("\n按任意键继续...");getch();putchar('\n');}while(choice!='0');}elseprintf("\n无该学生的信息。\n\n");}return head;}void Write_Data(struct stu_inf *head)//学生信息写入到文件{FILE *fp;struct stu_inf *p;if((fp=fopen("学生信息.txt","w"))==NULL){printf("\n*************\n");printf("文件创建失败。\n\n");printf("*************\n");return;}fprintf(fp,"学生总数:%d\n",STU_SUM);if(STU_SUM!=0)fprintf(fp,"\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t电话\tE-mail\n");for(p=head;p!=NULL;p=p->next)fprintf(fp,"%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n",p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email);fclose(fp);/*printf("\n*************\n");printf("文件写入成功。\n");printf("*************\n");*/}struct stu_inf *Read_Data()//从文件读入学生信息{FILE *fp;struct stu_inf *p,*phead,*head;if((fp=fopen("学生信息.txt","r"))==NULL){/*printf("\n*************\n");printf("文件读取失败。\n");printf("*************\n");*/return NULL;}/*printf("\n*************\n");printf("文件读取成功。\n");printf("*************\n");*/fscanf(fp,"学生总数:%d\n",&STU_SUM);if(STU_SUM==0)return NULL;fscanf(fp,"\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t电话\tE-mail\n");head=phead=p=(struct stu_inf *)malloc(LEN);fscanf(fp,"%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n",&p->number,p->name,&p->age,p->sex,&p->year,&p->month,p->address,p->tel,p->email);while(!feof(fp)){p=(struct stu_inf *)malloc(LEN);fscanf(fp,"%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n",&p->number,p->name,&p->age,p->sex,&p->year,&p->month,p->address,p->tel,p->email);phead->next=p;phead=phead->next;}phead->next=NULL;fclose(fp);return head;}

也希望能帮到正在做实训报告的你,欢迎留言区讨论。

分享:C语言学生成绩管理系统设计《C语言程序设计》实训报告

扫描下方公众号,发送成绩系统4个字,获取下载实训源码

扫描上方二维码,回复999直接获取作者之前收藏的学习资源,谢谢网友们的分享。

回复系统大全,即可获得关于C语言管理系统比较全面的文章内容,覆盖全网(有点夸张,随时更新,没获取到的朋友直接留言告诉一声)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。