大一刚刚放假,感觉这个学期还是学了不少东西的,一直对这个学期做个总结与回顾,就从写的第一个系统开始吧。
———————————————————————————————————————————
系统其实第一个版本是实验室对我们的一个小作业,要求不高,但是c才基本自学学完,学了单链表就开始写,大概花了一个下午吧,但是基础的增删查改功能还是有的
#include#include #include #include #include #include typedef struct std { char name[10]; char id[6]; float s[6]; float t;//总分 float a;//平均 struct std* pnext; }std,*pstd; pstd input()//创建 { int n; int i; float x; char a[10]; char b[6]; printf("请输入学生个数:n"); scanf("%d", &n); pstd ph = (pstd)malloc(sizeof(std));//头指针 pstd pt=ph;//尾指针 pt->pnext = NULL;//尾指针为空 for ( i = 1; i <= n; i++) { pstd pn = (pstd)malloc(sizeof(std));//开辟空间 //数据输入 printf("请输入第%d个学生的名字:n",i); scanf("%s", a); strcpy(pn->name, a); printf("请输入第%d个学生的学号(6位):n", i); scanf("%s", b); strcpy(pn->id, b); printf("请输入第%d个学生的语文成绩:n", i); scanf("%f", &x); pn->s[0] = x; printf("请输入第%d个学生的数学成绩:n", i); scanf("%f", &x); pn->s[1] = x; printf("请输入第%d个学生的英语成绩:n", i); scanf("%f", &x); pn->s[2] = x; printf("请输入第%d个学生的物理成绩:n", i); scanf("%f", &x); pn->s[3] = x; printf("请输入第%d个学生的化学成绩:n", i); scanf("%f", &x); pn->s[4] = x; printf("请输入第%d个学生的生物成绩:n", i); scanf("%f", &x); pn->s[5] = x; pn->t = pn->s[0] + pn->s[1] + pn->s[2] + pn->s[3] + pn->s[4] + pn->s[5]; pn->a = pn->t / 6.0; pt->pnext = pn;//上次循环之前的尾指针指向新创建的节点 pn->pnext = NULL;//新节点的指针域为空 pt = pn;//新节点为尾节点 system("cls"); } return ph; } void out(pstd p)//输出 { pstd pr = p->pnext; while (pr) { printf("姓名:%s ", pr->name); printf("学号:%s ", pr->id); printf("语文:%5.2f ", pr->s[0]); printf("数学:%5.2f ", pr->s[1]); printf("英语:%5.2f ", pr->s[2]); printf("物理:%5.2f ", pr->s[3]); printf("化学:%5.2f ", pr->s[4]); printf("生物:%5.2f ", pr->s[5]); printf("总分:%5.2f", pr->t); printf("平均:%5.2f", pr->a); printf("n"); pr = pr->pnext; } } void sort_s1(pstd p)//低到高排序(用的是冒泡,参考的别人的代码) { pstd pur, cur, next, end; end = NULL; while (p->pnext != end) { for (pur = p, cur = pur->pnext, next = cur->pnext; next != end; pur = pur->pnext, cur = cur->pnext, next = next->pnext) { if (cur->t > next->t) { pur->pnext = next; cur->pnext = next->pnext; next->pnext = cur; pstd m = cur; cur = next; next = m; } } end = cur; } } void sort_s2(pstd p)//高到低 { { pstd pur, cur, next, end; end = NULL; while (p->pnext != end) { for (pur = p, cur = pur->pnext, next = cur->pnext; next != end; pur = pur->pnext, cur = cur->pnext, next = next->pnext) { if (cur->t < next->t) { pur->pnext = next; cur->pnext = next->pnext; next->pnext = cur; pstd m = cur; cur = next; next = m; } } end = cur; } } } void sort_byname(pstd p)//姓名排序 { pstd pur, cur, next, end; end = NULL; while (p->pnext != end) { for (pur = p, cur = pur->pnext, next = cur->pnext; next != end; pur = pur->pnext, cur = cur->pnext, next = next->pnext) { if (strcmp(cur->name,next->name)>0) { pur->pnext = next; cur->pnext = next->pnext; next->pnext = cur; pstd m = cur; cur = next; next = m; } } end = cur; } } void sort_byid(pstd p)//学号排序 { pstd pur, cur, next, end; end = NULL; while (p->pnext != end) { for (pur = p, cur = pur->pnext, next = cur->pnext; next != end; pur = pur->pnext, cur = cur->pnext, next = next->pnext) { if (strcmp(cur->id, next->id) > 0) { pur->pnext = next; cur->pnext = next->pnext; next->pnext = cur; pstd m = cur; cur = next; next = m; } } end = cur; } } void outone(pstd p)//通过一些其他方法找到节点的地址,进行输出 { if(p==NULL) { printf("别找了洗洗睡吧n"); } else { pstd pr = p; printf("姓名:%s ", pr->name); printf("学号:%s ", pr->id); printf("语文:%5.2f ", pr->s[0]); printf("数学:%5.2f ", pr->s[1]); printf("英语:%5.2f ", pr->s[2]); printf("物理:%5.2f ", pr->s[3]); printf("化学:%5.2f ", pr->s[4]); printf("生物:%5.2f ", pr->s[5]); printf("总分:%5.2f", pr->t); printf("平均:%5.2f", pr->a); printf("n"); } } pstd fundname(pstd p) { int f = 0; int l=0; char n[10]; printf("请输入您要查找的名字:n"); scanf("%s", n); pstd pr = p->pnext; while (pr!=NULL) { if (strcmp(pr->name,n)==0) { f ++; return pr; } pr = pr->pnext; } if (f == 0) printf("对不起查无此人n"); return NULL; } pstd fundid(pstd p) { int f = 0; int l=0; char i[6]; printf("请输入您要查找的学号:n"); scanf("%s", i); pstd pr = p->pnext; while (pr!=NULL) { if (strcmp(pr->id,i) == 0) { f ++; return pr; } pr = pr->pnext; } if (f == 0) printf("对不起,查无此人n"); return NULL; } void deletes(pstd p,pstd ps) { pstd pr = p; while (pr->pnext != ps) { pr = pr->pnext; } pstd pt = pr->pnext; pr->pnext = ps->pnext; free(pt); pt = NULL; } void add(pstd p) { pstd ph = p->pnext; while (ph->pnext != NULL) { ph = ph->pnext; } int n; int i; float x; char a[10]; char b[6]; printf("请输入添加学生个数:n"); scanf_s("%d", &n); pstd pt = ph;//尾指针 pt->pnext = NULL;//尾指针为空 for ( i = 1; i <= n; i++) { pstd pn = (pstd)malloc(sizeof(std));//开辟空间 //数据输入 printf("请输入第%d个添加学生的名字:n", i); scanf("%s", a); strcpy(pn->name, a); printf("请输入第%d个添加学生的学号(6位):n", i); scanf("%s", b); strcpy(pn->id, b); printf("请输入第%d个添加学生的语文成绩:n", i); scanf("%f", &x); pn->s[0] = x; printf("请输入第%d个添加学生的数学成绩:n", i); scanf("%f", &x); pn->s[1] = x; printf("请输入第%d个添加学生的英语成绩:n", i); scanf("%f", &x); pn->s[2] = x; printf("请输入第%d个添加学生的物理成绩:n", i); scanf("%f", &x); pn->s[3] = x; printf("请输入第%d个添加学生的化学成绩:n", i); scanf("%f", &x); pn->s[4] = x; printf("请输入第%d个添加学生的生物成绩:n", i); scanf("%f", &x); pn->s[5] = x; pn->t = pn->s[0] + pn->s[1] + pn->s[2] + pn->s[3] + pn->s[4] + pn->s[5]; pn->a = pn->t / 6.0; pt->pnext = pn;//上次循环之前的尾指针指向新创建的节点 pn->pnext = NULL;//新节点的指针域为空 pt = pn;//新节点为尾节点 system("cls"); } } void precent(pstd p) { pstd pr=p->pnext ; int a=0,b=0,c=0,d=0,e=0; float t; while(pr) { if(pr->s[0]>=90) a++; else if(pr->s[0]>=80&&pr->s[0]<90) b++; else if(pr->s[0]>=70&&pr->s[0]<80) c++; else if(pr->s[0]>=60&&pr->s[0]<70) d++; else e++;pr=pr->pnext; } t=a+b+c+d+e; printf("语文:n优秀:%d %.2f%% 良好:%d %.2f%% 中等:%d %.2f%% 及格:%d %.2f%% 不及格:%d %.2f%% n",a,a*100.0/t,b,b*100.0/t,c,c*100.0/t,d,d*100.0/t,e,e*100.0/t); a=0;b=0;c=0;d=0;e=0; pr=p->pnext; while(pr) { if(pr->s[1]>=90) a++; else if(pr->s[1]>=80&&pr->s[1]<90) b++; else if(pr->s[1]>=70&&pr->s[1]<80) c++; else if(pr->s[1]>=60&&pr->s[1]<70) d++; else e++;pr=pr->pnext; } t=a+b+c+d+e; printf("数学:n优秀:%d %.2f%% 良好:%d %.2f%% 中等:%d %.2f%% 及格:%d %.2f%% 不及格:%d %.2f%% n",a,a*100.0/t,b,b*100.0/t,c,c*100.0/t,d,d*100.0/t,e,e*100.0/t); a=0;b=0;c=0;d=0;e=0; pr=p->pnext; while(pr) { if(pr->s[2]>=90) a++; else if(pr->s[2]>=80&&pr->s[2]<90) b++; else if(pr->s[2]>=70&&pr->s[2]<80) c++; else if(pr->s[2]>=60&&pr->s[2]<70) d++; else e++;pr=pr->pnext; } t=a+b+c+d+e; printf("英语:n优秀:%d %.2f%% 良好:%d %.2f%% 中等:%d %.2f%% 及格:%d %.2f%% 不及格:%d %.2f%% n",a,a*100.0/t,b,b*100.0/t,c,c*100.0/t,d,d*100.0/t,e,e*100.0/t); a=0;b=0;c=0;d=0;e=0; pr=p->pnext; while(pr) { if(pr->s[3]>=90) a++; else if(pr->s[3]>=80&&pr->s[3]<90) b++; else if(pr->s[3]>=70&&pr->s[3]<80) c++; else if(pr->s[3]>=60&&pr->s[3]<70) d++; else e++;pr=pr->pnext; } t=a+b+c+d+e; printf("物理:n优秀:%d %.2f%% 良好:%d %.2f%% 中等:%d %.2f%% 及格:%d %.2f%% 不及格:%d %.2f%% n",a,a*100.0/t,b,b*100.0/t,c,c*100.0/t,d,d*100.0/t,e,e*100.0/t); a=0;b=0;c=0;d=0;e=0; pr=p->pnext; while(pr) { if(pr->s[4]>=90) a++; else if(pr->s[4]>=80&&pr->s[4]<90) b++; else if(pr->s[4]>=70&&pr->s[4]<80) c++; else if(pr->s[4]>=60&&pr->s[4]<70) d++; else e++; pr=pr->pnext; } t=a+b+c+d+e; printf("化学:n优秀:%d %.2f%% 良好:%d %.2f%% 中等:%d %.2f%% 及格:%d %.2f%% 不及格:%d %.2f%% n",a,a*100.0/t,b,b*100.0/t,c,c*100.0/t,d,d*100.0/t,e,e*100.0/t); a=0;b=0;c=0;d=0;e=0; pr=p->pnext; while(pr) { if(pr->s[5]>=90) a++; else if(pr->s[5]>=80&&pr->s[5]<90) b++; else if(pr->s[5]>=70&&pr->s[5]<80) c++; else if(pr->s[5]>=60&&pr->s[5]<70) d++; else e++;pr=pr->pnext; } t=a+b+c+d+e; printf("生物:n优秀:%d %.2f%% 良好:%d %.2f%% 中等:%d %.2f%% 及格:%d %.2f%% 不及格:%d %.2f%% n",a,a*100.0/t,b,b*100.0/t,c,c*100.0/t,d,d*100.0/t,e,e*100.0/t); } void save(pstd p) { pstd pr=p->pnext; if(pr==NULL) return; FILE *fp; if((fp=fopen("xdzn.txt","wt"))==NULL) { printf("储存失败n"); return; } while(pr) { fprintf(fp,"%s %s %f %f %f %f %f %f %f %fn",pr->name,pr->id,pr->s[0],pr->s[1],pr->s[2],pr->s[3],pr->s[4],pr->s[5],pr->t,pr->a); pr=pr->pnext; } fclose(fp); fp=NULL; } pstd read() { int end; pstd ph=(pstd)malloc(sizeof(std)); pstd pt=ph; pt->pnext=NULL; FILE* fp; if((fp=fopen("xdzn.txt","r+"))==NULL) { printf("读取失败n"); return; } while(1) { pstd pn=(pstd)malloc(sizeof(std)); end=fscanf(fp,"%s %s %f %f %f %f %f %f %f %fn",&pn->name,&pn->id,&pn->s[0],&pn->s[1],&pn->s[2],&pn->s[3],&pn->s[4],&pn->s[5],&pn->t,&pn->a); if(end==EOF) { free(pn); pn=NULL; return ph; } pt->pnext=pn; pn->pnext=NULL; pt=pn; } free(fp); fp=NULL; return ph; } void welcome() { printf("|**************************************|n"); printf("|***************虚动智能***************|n"); printf("|**************************************|n"); printf("|***************震撼上线***************|n"); printf("|**************************************|n"); printf("|***************为您服务***************|n"); system("pause"); system("cls"); } void outtotal(pstd p) { float n=0; float c=0; pstd pr=p->pnext; while(pr) { n+=pr->s[0]; c++; pr=pr->pnext; } printf("语文总分为%5.2f 平均分为%5.2fn",n,n/c); pr=p->pnext; n=0;c=0; while(pr) { n+=pr->s[1]; c++; pr=pr->pnext; } printf("数学总分为%5.2f 平均分为%5.2fn",n,n/c); pr=p->pnext; n=0;c=0; while(pr) { n+=pr->s[2]; c++; pr=pr->pnext; } printf("英语总分为%5.2f 平均分为%5.2fn",n,n/c); pr=p->pnext; n=0;c=0; while(pr) { n+=pr->s[3]; c++; pr=pr->pnext; } printf("物理总分为%5.2f 平均分为%5.2fn",n,n/c); pr=p->pnext; n=0;c=0; while(pr) { n+=pr->s[4]; c++; pr=pr->pnext; } printf("化学总分为%5.2f 平均分为%5.2fn",n,n/c); pr=p->pnext; n=0;c=0; while(pr) { n+=pr->s[5]; c++; pr=pr->pnext; } printf("生物总分为%5.2f 平均分为%5.2fn",n,n/c); } pstd change(pstd p) { if(p==NULL) return; pstd pn=p; float x; printf("请输入待修改学生的语文成绩:n"); scanf("%f", &x); pn->s[0] = x; printf("请输入待修改学生的数学成绩:n"); scanf("%f", &x); pn->s[1] = x; printf("请输入待修改学生的英语成绩:n"); scanf("%f", &x); pn->s[2] = x; printf("请输入待修改学生的物理成绩:n"); scanf("%f", &x); pn->s[3] = x; printf("请输入待修改学生的化学成绩:n"); scanf("%f", &x); pn->s[4] = x; printf("请输入待修改学生的生物成绩:n"); scanf("%f", &x); pn->s[5] = x; pn->t = pn->s[0] + pn->s[1] + pn->s[2] + pn->s[3] + pn->s[4] + pn->s[5]; pn->a = pn->t / 6.0; } void xzjm() { printf("____________________________________________________________n"); printf("|1.Input record |n"); printf("|2.Caculate total and average score of every course |n"); printf("|3.Caculate total and average score of every student |n"); printf("|4.Sort in descebding order by total score of every student|n"); printf("|5.Sort in ascending order by total score of every student |n"); printf("|6.Sort in ascending order by number |n"); printf("|7.Sort in dictinoary order by name |n"); printf("|8.Search by id |n"); printf("|9.cearch by number |n"); printf("|10.Statistic analysis for every course |n"); printf("|11.List record |n"); printf("|12.Write to a file |n"); printf("|13.Read from a file |n"); printf("|14.Delete by name |n"); printf("|15.Delete by id |n"); printf("|16.Add |n"); printf("|17.Change |n"); printf("|0.Exit |n"); printf("|__________________________________________________________|n"); printf("Please enter your choice:n"); } void pai(pstd p,pstd pr) { if(pr==NULL) { return; } int c=0; sort_s2(p); pstd pt=p; while(pt!=pr) { pt=pt->pnext; c++; } if (pt->pnext != NULL){ printf("排名:%dn", c); outone(pr); return; } } int main() { welcome(); pstd head=NULL; while(1) { xzjm(); int x; scanf("%d",&x); switch(x) { case 1: system("cls");head=input();system("cls");break; case 2: system("cls");outtotal(head);system("pause");break; case 3: system("cls");out(head);system("pause");break; case 4: system("cls");sort_s2(head); out(head);system("pause");break; case 5: system("cls");sort_s1(head); out(head);system("pause");break; case 6: system("cls");sort_byid(head); out(head);system("pause");break; case 7: system("cls");sort_byname(head); out(head);system("pause");break; case 8: system("cls");pai(head,fundid(head));system("pause");break; case 9: system("cls");pai(head,fundname(head));system("pause");break; case 10: system("cls");precent(head);system("pause");break; case 11: system("cls");out(head);system("pause");break; case 12: system("cls");save(head);system("pause");break; case 13: system("cls"); free(head); head = NULL; head = read(); out(read()); system("pause"); break; case 14: system("cls");deletes(head,fundname(head));system("pause");break; case 15: system("cls");deletes(head,fundid(head));system("pause");break; case 16: system("cls");add(head);system("pause");break; case 17: system("cls");change(fundname(head));system("pause");break; case 0: system("cls");printf("感谢使用n");Sleep(1000);system("pause"); exit(-1);break; default: system("cls");printf("手抖了?n再试试?nnn");break; } } return 0; }
写得有点简陋,里面好像也有些bug,不给我也记不清了,希望可以给大家一个参考
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)