1、C语言学生信息管理系统代码312020年4月19日文档仅供参考X X 师 范 大 学 实 验 报 告课 程 C语言课程设计 任课老师 学 号 姓 名 院 系 _年_月至_年_月 注意事项1. 使用C语言,代码已在vs中运行过,能够运行(主要功能都能实现)2. 需求分析,前期设计都没写,请同学们自己完成3. 附带有 student.txt 文件,将其移动至 F:stu 文件夹中,运行程序时可直接选 6号指令,从中读取学生信息。如果没有该txt文件(可能会在上传过程中丢失),仍需在F盘下新建stu文件夹,各文件将保存于该文件夹中4. 按word格式输出尚未设计好,有兴趣可自己完成5. 按excel
2、格式输出,完成后需自行调整相应列宽(拉宽),使内容美观6. 从下一页开始,复制余下全文,粘贴即可运行#include#define M 30 /班级总人数,暂定30,可修改#define N 3 /课程成绩门数,暂定3,可修改 int inputstu(struct student stu, int m, int n);void prinstu(struct student stu, int m, int n);int sortsno(struct student stu, int m);int sortage(struct student stu, int m);int sortmark(s
3、truct student stu,int sm, int m, int n);void prinsort(struct student stu, int m, int n);int writefile(struct student stu, FILE *fp, int m, int n);int readfile(struct student stu, FILE *fp, int m, int n);int fprinword(struct student stu, FILE *fp, int m, int n);int fprinexcel(struct student stu, FILE
4、 *fp, int m, int n);int seachsno(struct student stu,long sno, int m,int n);int seachsname(struct student stu,char sname, int m, int n);int desno(struct student stu, long sno, int m);int desname(struct student stu, char sname, int m);int cutin(struct student stu, int m, int n); struct student int tur
5、n; long sno; char sname20; char sgrade10; char sbirth10; int smarkN; void main() int i = 0; int con1 = 0; int con2 = 0; long sno; char sname20; FILE *fp = NULL; struct student stuM; for (i = 0; i M; i+) stui.turn = -1; do printf(nn*n); printf( n * 学生信息管理系统 *nn); printf( * 请按提示输入相应命令: *nn); printf( 1
6、 键盘输入所有学生的基本信息n); printf( 2 屏幕输出所有学生的基本信息n); printf( 3 子菜单:按一定顺序对学生进行排序n); printf( 4 按顺序屏幕输出学生信息n); printf( 5 保存学生信息(二进制文件)n); printf( 6 从上次保存的二进制文件中读取学生信息n); printf( 7 子菜单:将学生信息保存为文本文档(人工阅读)n); printf( 8 子菜单:对单个学生的插入删除查询修改n); printf( -1 退出系统n); scanf(%d, &con1); switch (con1) case 1: printf(n* 注意!
7、*n); printf( 继续进行输入会覆盖原数据!n); printf( 第一次使用本软件或需重新写信息请继续:n ); printf( 1 继续n); printf( -1 返回n); scanf(%d, &con2); if (con2 = 1) inputstu(stu, M, N); break; case 2:prinstu(stu, M, N); break; case 3: do printf(n*n); printf( 1 按学号顺序进行排序n); printf( 2 按年龄从小到大排序n); printf( 3 按总成绩由高到低排序n); printf( -1 返回上一级菜
8、单n); scanf(%d, &con2); switch (con2) case 1: sortsno(stu, M); con2 = 0; break; case 2: /sortage(stu, M); break; case 3: int smM; sortmark(stu, sm, M, N); break; case -1:break; default: printf(二级命令输入错误,请重试!n); fflush(stdin); while (con2 != -1); break; case 4:prinsort(stu, M, N); break; case 5:writefi
9、le(stu, fp, M, N); break; case 6:readfile(stu, fp, M, N); break; case 7: printf(n*n); printf( 1 将学生信息输出为txt文档,路径:F:stustudent.txtn); printf( 2 将学生信息输出为word文档, 路径:F:stustudent.doc n); printf( 3 将学生信息输出为excel文档, 路径:F:stustudent.xls n); printf( -1 返回上一级菜单n); scanf(%d, &con2); switch (con2) case 1: brea
10、k; case 2: fprinword(stu, fp, M, N); break; case 3: fprinexcel(stu, fp, M, N); break; break; case 8: do printf(n*nn); printf( 1 按学号查询单个学生n); printf( 2 按姓名查询单个学生n); printf( 3 按学号删除单个学生n); printf( 4 按姓名删除单个学生n); printf( 5 插入单个学生信息n); printf(-1 返回主菜单n); scanf(%d, &con2); switch (con2) case 1: printf(请输
11、入单个学号:n); scanf(%10ld, &sno); seachsno(stu, sno, M, N); break; case 2: printf(请输入单个学生姓名:n); scanf(%20s,sname); seachsname(stu, sname, M, N); break; case 3: printf(请输入单个学号:n); scanf(%10ld,&sno); desno(stu, sno, M); break; case 4: printf(请输入单个学生姓名:n); scanf(%s, sname); desname(stu, sname, M); break; c
12、ase 5: cutin(stu, M, N); break; default: printf(二级指令错误,请重新输入!n); break; while (con2 != -1); case -1:printf(感谢使用本系统!n); break; default: printf(一级命令输入错误,请重试); fflush(stdin); break; while (con1 != -1); /输入学生的基本信息int inputstu(struct student stu,int m,int n)int i = 0;int j = 0;printf(请按说明输入学生信息:n);while
13、(i m)printf(请输入第%d个学生的学号,姓名,班级,出生日期:n, i + 1);scanf(%10ld%20s%10s%10s, &stui.sno, &stui.sname, &stui.sgrade, &stui.sbirth);for (j = 0; j n; j+)printf(请输入第%d个学生的第%d门成绩n,i+1,j+1);scanf(%d, &stui.smarkj);i+;return i;/屏幕输出学生信息void prinstu(struct student stu, int m, int n)int i = 0;int j = 0;printf(*n);p
14、rintf(学生基本信息如下:n);printf( 学号 姓名 班级 出生年月 成绩1 成绩2 成绩3n);while (i m) if (stui.sno = 0)i+;continue;printf(%10ld %20s%10s %10s , stui.sno, stui.sname, stui.sgrade, stui.sbirth);for (j = 0; j n; j+)printf( %d , stui.smarkj);printf(n);i+;/按学号顺序进行排序int sortsno(struct student stu,int m)int i = 0;int j = 0;in
15、t s;long snoM;for (i = 0; i M; i+)snoi = stui.sno;for (i = 0; i m; i+)for (j = i+1; j snoj)s = snoj;snoj = snoi;snoi = s;for (i = 0; i m; i+)for (j = 0; j m; j+)if (stuj.sno = snoi)stuj.turn = i;return i;/按年龄对学生进行排序;int sortage(struct student stu, int m)/按总成绩由高到低排序int sortmark(struct student stu,int
16、 sm, int m,int n)int i = 0;int j = 0;int s = 0;for (i = 0; i m; i+)smi = 0;for (i = 0; i m; i+)for (j = 0; j n; j+)smi = smi + stui.smarkj;for (i = 0; i m; i+)for (j = i + 1; j m; j+)s = smi;if (s smj)s =j;sms = 0;stus.turn = i;return i;/按顺序屏幕输出void prinsort(struct student stu,int m,int n)int i = 0;
17、int j = 0;int k = 0;printf(n*n);printf(按排序,学生基本信息如下:n);printf( 学号 姓名 班级 出生年月 成绩1 成绩2 成绩3n);while (k m)if (stui.sno = 0)continue;for (i = 0; i m; i+)if (stui.turn = k)printf(%10ld %20s%10s %10s , stui.sno, stui.sname, stui.sgrade, stui.sbirth);for (j = 0; j n; j+)printf( %d , stui.smarkj);printf(n);k
18、+;/写数据进二进制文件 int writefile(struct student stu,FILE *fp,int m,int n)int i = 1;fp = fopen(f:stustudent.txt, wb);if (fp = NULL)printf(打开文件失败!n);exit(0);fwrite(&stu0,sizeof(struct student),m,fp);i = fclose(fp);return i;/从二进制中读取学生信息int readfile(struct student stu, FILE *fp, int m, int n)int i = 1;fp = fo
19、pen(f:stustudent.txt, rb);if (fp = NULL)printf(打开文件失败!n);exit(0);fread(&stu0, sizeof(struct student), m, fp);i = fclose(fp);return i;/将学生信息写入word文档,保存于 F:stustudent.doc int fprinword(struct student stu, FILE *fp, int m, int n)int i = 0;int j = 0;fp = fopen(F:stustudent.doc,w);if (fp = NULL)printf(文件
20、打开失败!);exit(0);while (i m)if (stui.sno = 0);continue;fprintf(fp,%10ld %20s%10s%10s, stui.sno, stui.sname, stui.sgrade, stui.sbirth);for (j = 0; j n; j+)fprintf(fp, %d , stui.smarkj);printf(n);i+;fclose(fp);return i;/将学生信息写入excel文档,保存于 F:stustudent.xls int fprinexcel(struct student stu, FILE *fp, int
21、 m, int n)int i = 0;int j = 0;char t = t;char lin20=成绩;char str420;strcpy(str0, 学号);strcpy(str1, 姓名);strcpy(str2, 班级);strcpy(str3, 生日);fp = fopen(F:stustudent.xls, w);if (fp = NULL)printf(文件打开失败!);exit(0);fprintf(fp, %s%c%s%c%s%c%s, str0, t, str1, t, str2, t, str3);for (i = 0; i n; i+)fprintf(fp, %c
22、 %s%d, t, lin, i+1);fprintf(fp, n);i = 0;while (i m)if (stui.sno = -1)continue;fprintf(fp, %10ld%c%20s%c%10s%c%10s, stui.sno,t, stui.sname,t, stui.sgrade,t, stui.sbirth);for (j = 0; j n; j+)fprintf(fp, %c%d, t,stui.smarkj);fprintf(fp,n);i+;fclose(fp);return i;/按学号查询单个学生int seachsno(struct student st
23、u,long sno,int m,int n)int i = 0;int j = 0;for (i = 0; i m; i+)if (stui.sno = sno)printf(按学号查询到的学生基本信息如下:n);printf( 学号 姓名 班级 出生年月 成绩1 成绩2 成绩3n);printf(%10ld %20s%10s %10s , stui.sno, stui.sname, stui.sgrade, stui.sbirth);for (j = 0; j n; j+)printf( %d , stui.smarkj);printf(n);break;return i;/按姓名查询单个
24、学生int seachsname(struct student stu,char sname, int m, int n)int i = 0;int j = 0;int s = -1;for (i = 0; i m; i+)s = strcmp(stui.sname, sname);if (s = 0)printf(按姓名查询到的学生基本信息如下:n);printf( 学号 姓名 班级 出生年月 成绩1 成绩2 成绩3n);printf(%10ld %20s%10s %10s , stui.sno, stui.sname, stui.sgrade, stui.sbirth);for (j =
25、0; j n; j+)printf( %d , stui.smarkj);printf(n);break;return i; /按学号删除单个学生信息desno(struct student stu, long sno,int m)int i = 0;for (i = 0; i m; i+)if (stui.sno = sno)stui.sno = 0;break;return i;/按姓名删除单个学生int desname(struct student stu, char sname, int m)int i = 0;int j = 0;int s = -1;for (i = 0; i m;
26、 i+)s = strcmp(stui.sname, sname);if (s = 0)stui.sno = 0;break;return i;/插入单个学生int cutin(struct student stu,int m,int n)int i = 0;int j = 0;for (i=0;im;i+)if (stui.sno = 0)printf(请输入第%d个学生的学号,姓名,班级,出生日期:n, i + 1);scanf(%10ld%20s%10s%10s, &stui.sno, &stui.sname, &stui.sgrade, &stui.sbirth);for (j = 0; j n; j+)printf(请输入第%d个学生的第%d门成绩n, i + 1, j + 1);scanf(%d, &stui.smarkj);break;if (i = m - 1)printf(暂时没有空结构!n);return i;
©2010-2024 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100