#include#include #include #include typedef struct Student{ char name[20]; int age; int stunum; int score; }Student; typedef struct LNode{ Student stu; LNode* Next; }LNode; LNode* Ptrl = NULL; void Panel(); void Input(); void Printout(); void Find(); void Modify(); void Delete(); void Count(); void Save(); void Read(); int main() { while(1){ Panel(); char cmp = getch(); switch (cmp){ case '1': Input(); break; case '2': Printout(); break; case '3': Find(); break; case '4': Modify(); break; case '5': Delete(); break; case '6': Count(); break; case '7': Save(); break; case '8': Read(); break; case '0': printf("The system is over!n"); return 0; } } return 0; } void Panel() { printf("***********************n"); printf("******功能清单如下*****n"); printf("*** [1]录入学生信息 ***n"); printf("*** [2]打印学生信息 ***n"); printf("*** [3]查找学生信息 ***n"); printf("*** [4]修改学生信息 ***n"); printf("*** [5]删除学生信息 ***n"); printf("*** [6]统计学生人数 ***n"); printf("*** [7]保存学生信息 ***n"); printf("*** [8]读入学生信息 ***n"); printf("*** [0]退出学生系统 ***n"); printf("***********************n"); } void Input() { LNode* p = (LNode*)malloc(sizeof(LNode)); p->Next = NULL; if(Ptrl == NULL){ Ptrl = p; } else{ p->Next = Ptrl; Ptrl = p; } printf("Please input student's name:n"); scanf("%s",p->stu.name); printf("Please input student's age:n"); scanf("%d",&p->stu.age); printf("Please input student's studentnumber:n"); scanf("%d",&p->stu.stunum); printf("Please input student's score:n"); scanf("%d",&p->stu.score); printf("The operation is finished.n"); system("pause"); system("cls"); } void Printout() { LNode* p = Ptrl; if(p != NULL){ while(p != NULL){ printf("**************************************n"); printf("nametagetstudentnumbertscoren"); printf("%st%dt%dtt%dn", p->stu.name, p->stu.age, p->stu.stunum, p->stu.score); p = p->Next; } printf("**************************************n"); } else{ printf("Empty!n"); } system("pause"); system("cls"); } void Find() { char name[20]; int stunum; LNode* p=Ptrl; printf("Please input the name of the student which you want to find.n"); scanf("%s",name); printf("Please input the studentnumber of the student which you want to find.n"); scanf("%d",&stunum); while(p != NULL){ if(p->stu.stunum == stunum || 0 ==strcmp(p->stu.name,name)){ printf("nametagetstudentnumbertscoren"); printf("%st%dt%dtt%dn", p->stu.name, p->stu.age, p->stu.stunum, p->stu.score); break; } p = p->Next; } if(p == NULL){ printf("This information does not exist.n"); } system("pause"); system("cls"); } void Modify() { int stunum; LNode* p = Ptrl; printf("Please input the studentnumber of the student which you want to modify.n"); scanf("%d",&stunum); while(p != NULL){ if(p->stu.stunum == stunum){ printf("The changed name:n"); scanf("%s",p->stu.name); printf("The changed studentname:n"); scanf("%d",&p->stu.stunum); printf("The changed score:n"); scanf("%d",&p->stu.score); break; } p = p->Next; } if(p == NULL){ printf("This information does not exist.n"); } system("pause"); system("cls"); } void Delete() { int stunum; LNode* d1; LNode* d2; printf("Please input the studentnumber of the student which you want to delete.n"); scanf("%d",&stunum); if(Ptrl->stu.stunum == stunum){ d1 = Ptrl; Ptrl = Ptrl->Next; free(d1); printf("The operation is finished.n"); system("pause"); system("cls"); } else{ LNode* p = Ptrl; while(p->Next != NULL){ if(p->Next->stu.stunum == stunum){ d2 = p->Next; p->Next = p->Next->Next; free(d2); printf("The operation is finished.n"); } } if(p == NULL){ printf("This information does not exist.n"); } system("pause"); system("cls"); } } void Count() { LNode* p = Ptrl; int count=0; while(p != NULL){ p = p->Next; count++; } printf("The total number of the students is %dn",count); system("pause"); system("cls"); } void Save() { FILE* fp = fopen("D:\text2.txt","w"); LNode* p; if(fp == NULL){ printf("Failed to open file.n"); system("pause"); system("cls"); return; } p = Ptrl; while(p != NULL){ fwrite(&p->stu,sizeof(Student),1,fp); p = p->Next; } fclose(fp); printf("Data is successfully saved.n"); system("pause"); system("cls"); } void Read() { FILE* fp = fopen("D:\text2.txt","r"); LNode* p; if(fp == NULL){ printf("Failed to open file.n"); system("pause"); system("cls"); return; } Student stu; while(fread(&stu,sizeof(Student),1,fp)){ p = (LNode*)malloc(sizeof(LNode)); p->Next == NULL; memcpy(p,&stu,sizeof(Student)); } if(Ptrl == NULL){ Ptrl = p; } else{ p->Next = Ptrl; Ptrl = p; } fclose(fp); printf("Data is successfully loaded.n"); system("pause"); system("cls"); }



