链表实现学籍管理系统(可保存)
链表实现学籍管理系统(可保存)#include#include#include#include
struct student{char name[30]; int num; char sex[10]; float math ; float english; float cyuyan; float pingjun;struct student *next;};void xieru();voidchaxun();void paixu();void shanchu();void charu();void main() { int b,flag=0; while(1) {printf("\n\t\t\t欢迎来到学生学籍统!\n");printf("\t\t\t-------------------------------\n");printf("\t\t\t1.输入学生的信息\n\n"); printf("\t\t\t2.查看录入的学生信息\n\n"); printf("\t\t\t3.按学生学号排序\n\n"); printf("\t\t\t4.删除一个学生的信息\n\n"); printf("\t\t\t5.插入一个学生信息\n\n"); printf("\t\t\t0.退出\n\n"); printf("\t\t\t请输入你的选择:");scanf("%d",&b);switch(b){case 1:xieru();break;case 2:chaxun();break;case 3:paixu();break;case 4:shanchu();break;case 5:charu();break;case 0:flag=1;break;default :printf("错误!");}if(flag) break; }}
void xieru()//写入{int i=0;char jx;struct student *head = NULL,*p1, *p2;FILE *fp;system("cls");p1=p2=(struct student*)malloc(sizeof (struct student) );printf("\n\n\n\n\t请按提示输入学生的个人信息:\n");while(1){printf("\n\t\t\t请输入学生姓名:");scanf("%s", p1->name); printf("\n\t\t\t请输入学生学号:");scanf("%d",&p1->num); printf("\n\t\t\t请输入学生性别:");scanf("%s", p1->sex); printf("\n\t\t\t请输入数学成绩:");scanf("%f",&p1->math); printf("\n\t\t\t请输入英语成绩:");scanf("%f",&p1->english); printf("\n\t\t\t请输入C语言成绩:");scanf("%f",&p1->cyuyan); p1->pingjun=(float)(p1->math+p1->english+p1->cyuyan)/3;if(head==NULL)head=p1;elsep2->next = p1;p2=p1;printf("\n\n\n\n\n\t若继续录入学生信息请输入Y或y 输入N或n返回选择界面\n");scanf("%s",&jx);if(jx=='N'||jx=='n')break;elsep1=(struct student*)malloc(sizeof (struct student) );}p1->next=NULL;system("cls");if((fp=fopen("student.txt","wb"))==NULL){printf("不能打开此文件!");exit(0);