您的当前位置:首页正文

学生成绩管理系统参考程序

2020-09-21 来源:易榕旅网
学生成绩管理系统参考程序

#include #include #include

#define MAXN 100 /*一个班最多的人数*/ #define MAXM 10 /*最多课程门数*/ char subject[MAXM][12]; /*保存所有课程名称*/ char number[MAXN][10]; /*保存全班学号*/ char name[MAXN][20]; /*保存全班姓名*/

float score[MAXN][MAXM]; /*保存全班所有课程成绩*/ float sum[MAXN]; /*保存全班总成绩*/ int n,m; /*n,m保存全班实际人数和课程数*/ void input(); void search(); void sort(); void save(); void load(); void print(); void main() { int select; while(1)

{

printf(\"1.成绩录入\\n\"); printf(\"2.成绩查询\\n\"); printf(\"3.成绩排序\\n\"); printf(\"4.成绩保存\\n\"); printf(\"5.成绩读取\\n\"); printf(\"6.成绩报表打印\\n\"); printf(\"0.退出\\n\");

printf(\"\\n请输入您的选择编号:\\n\"); scanf(\"%d\switch(select) {

case 1:input(); break; case 2: search();break; case 3:sort();break; case 4:save(); break; case 5:load(); break; case 6:print();break;

case 0:printf(\"谢谢您的使用。\\n\"); } } }

void input() /*输入成绩模块*/ { int i,j;

printf(\"请输入全班人数:\"); scanf(\"%d\

printf(\"请输入课程门数:\"); scanf(\"%d\

printf(\"请输入%d门课程名称\\n\for(j=0;jprintf(\"第%d门课程名称:\scanf(\"%s\}

printf(\"第%d个学生数据\\n\for(i=0;iprintf(\"请输入第%d个人的数据\\n\printf(\"学号:\"); scanf(\"%s\printf(\"姓名:\"); scanf(\"%s\

printf(\"%d门课程的成绩:\

sum[i]=0; /*边输入边统计总成绩*/ for(j=0;jprintf(\"%s:\scanf(\"%f\sum[i]=sum[i]+score[i][j]; } } }

void search() /*查询成绩模块*/ { int j; int search1(); int search2(); int select,index; while(1) {

printf(\"1.按学号查询\\n\"); printf(\"2.按姓名查询\\n\"); printf(\"0.返回\\n\");

printf(\"\\n请输入您的选择编号:\\n\"); scanf(\"%d\

switch(select) {

case 1:index=search1(); break; case 2:index=search2();break; case 0:return; }

if(index!=-1) {

printf(\"学号:%s\\n\printf(\"姓名:%s\\n\for(j=0;jprintf(\"%12s:\printf(\"%5.1f\\n\}

printf(\"\\n总成绩:%10.2f\printf(\"平均成绩:%10.2f\\n\}

else printf(\"没有这个同学。\\n\"); } }

int search1() /*按学号查询模块*/

{ int i;

char s_number[10];

printf(\"请输入要查询的学号:\"); scanf(\"%s\for(i=0;iif(strcmp(number[i],s_number)==0) break; if(iint search2() /*按姓名查询模块*/ { int i;

char s_name[10];

printf(\"请输入要查询的姓名:\"); scanf(\"%s\for(i=0;iif(strcmp(name[i],s_name)==0) break; if(ireturn i; else return -1; }

void sort() /*排序模块*/ {

void sort1(); void sort2(); void sort3(); int select; while(1) {

printf(\"1.按学号排序\\n\"); printf(\"2.按姓名排序\\n\"); printf(\"3.按总成绩排序\\n\"); printf(\"0.返回\\n\");

printf(\"\\n请输入您的选择编号:\\n\"); scanf(\"%d\switch(select) {

case 1:sort1();break; case 2:sort2();break; case 3:sort();break;

case 0:return; } } }

void sort1() /*按学号排序模块*/ { int i,j,k;

char x_number[10]; char x_name[20]; float x;

for(i=0;ifor(j=i+1;jif(strcmp(number[i],number[k])<0) k=j; if (k!=i) {

strcpy(x_number,number[i]); strcpy(number[i],number[k]); strcpy(number[k],x_number); strcpy(x_name,name[i]);

strcpy(name[i],name[k]); strcpy(name[k],x_name); for(j=0;jx=score[i][j]; score[i][j]=score[k][j]; score[k][j]=x; }

x=sum[i];sum[i]=sum[k];sum[k]=x; } }

printf(\"排序完毕.\\n\"); }

void sort2() /*按姓名排序模块*/ { int i,j,k;

char x_number[10]; char x_name[20]; float x;

for(i=0;ifor(j=i+1;jif(strcmp(name[j],name[k])<0) k=j; if(k!=i) {

strcpy(x_number,number[i]); strcpy(number[i],number[k]); strcpy(number[k],x_number); strcpy(name[i],name[k]); strcpy(name[k],x_name); for(j=0;jx=score[i][j]; score[i][j]=score[k][j]; score[k][j]=x; }

x=sum[i];sum[i]=sum[k];sum[k]=x; } }

printf(\"排序完毕.\\n\"); }

void sort3() /*按总成绩排序模块*/

{ int i,j,k;

char x_number[10]; char x_name[20]; float x;

for(i=0;ifor(j=i+1;jstrcpy(x_number,number[i]); strcpy(number[i],number[k]); strcpy(number[k],x_number); strcpy(x_name,name[i]); strcpy(name[i],name[k]); strcpy(name[k],x_name); for(j=0;jx=score[i][j];

score[i][j]=score[k][j]; score[k][j]=x; }

x=sum[i];sum[i]=sum[k];sum[k]=x; } }

printf(\"排序完毕.\\n\"); }

void save() /*保存成绩模块*/ { FILE *fp; char filename[20]; int i,j;

printf(\"请输入文件名: \"); scanf(\"%s\

if((fp=fopen(filename, \"w\"))==NULL) {

printf(\"打开文件失败.\\n\"); return; }

fprintf(fp, \"%d %d\for(j=0;jfprintf(fp, \"%s\for(i=0;ifprintf(fp, \"%s %s\for(j=0;jfprintf(fp, \"%5.1f\} fclose(fp);

printf(\"保存完毕.\\n\"); }

void load( ) /* 提取成绩模块{

FILE * fp; char filename[20]; int i,j;

printf (\"请输入文件名:\"); scanf(\"%s\

if ((fp=fopen(filename,\"r\"))==NULL) {

printf(\"文件不存在.\\n\"); return; }

*/ fscanf(fp,\"%d%d\for(j=0;jfscanf(fp,\"%s\for(i=0;ifscanf(fp,\"%s%s\ sum[i]=0; for(j=0;jfscanf(fp,\"%f\ sum[i]=sum[i]+score[i][j]; } } fclose(fp);

printf(\"提取完毕.\\n\"); }

void print() {

void print1(); void print2(); int select;

printf(\"1.屏幕显示报表\\n\");

printf(\"2.打印机打印报表\"); printf(\"0.返回\\n\");

printf(\"\\n请输入您的选择编号:\"); scanf(\"%d\ switch(select) { case 1:print1();break; case 2:print2();break; case 0:return;

}

}

void print1() /* 屏幕显示报表模块 { int i,j;

printf(\"成绩总表\\n\"); printf(\"学号姓名:\"); for (j=0;jprintf(\"%8s %8s\

*/ for (j=0;jprintf(\"%6.1f\

printf(\"%6.1f %6.2f\\n\ }

printf(\"显示完毕.\\n\"); }

void print2( ) /* 打印机打印报表模块 {

FILE * fp; int i,j;

printf(\"请准备好打印机,按任意键继续…\\n\"); scanf(\"% * c\");

if ((fp=fopen(\"prn\ {

printf(\"打印机没有准备好.\\n\"); return; }

fprintf(fp,\"成绩总表\\n\"); fprintf(fp,\"学 号 姓 名\\n\"); for (j=0;jfprintf(fp,\"%10s\fprintf(fp,\"总成绩 平均成绩\\n\");

*/ for(i=0;ifprintf(fp,\"%8s %8s\ for (j=0;jfprintf(fp,\"%6.1f\

fprintf(fp,\"%6.1f %6.2f\\n\ } fclose(fp);

printf(\"打印完毕.\\n\"); }

因篇幅问题不能全部显示,请点此查看更多更全内容