#include
#include
#include
#include
#include
#include
#define LEN1 sizeof(struct student)
#define NULL 0
struct student
{
char num[15]; //记录学号。
char name[15];//记录姓名。
char sex[6]; //记录性别。
struct student *next;
};
int toint(char string[4]) //定义一个函数,把数字字符串转化为整数。
{
int length,sum=0;
length=strlen(string);
for(int i=0;i
return sum/10;
}
int subject(FILE *fp) //定义一个函数,来通过文件找出科目数。
{
int n=0;
char str[40];
rewind(fp);//把文件指针返回到文件的开头。
do
{
fscanf(fp,"%s",str);
n++;
}while(strcmp(str,"total")!=0);
return n-6;
}
int judgefile(FILE *fp)//判断文件是否是上次录入的文件。
{
char str[40];
int i=0;
char c;
while(!feof(fp))
if(isprint(c=fgetc(fp))&&(c!=32))
i=1;
rewind(fp);
do
{
fscanf(fp,"%s",str);
if(strcmp("total",str)==0)
i=2;
}while(!feof(fp));
switch(i)
{
case 0:printf("\n此文件是空的!\n\n");return 0;
case 1:printf("\n此文件不是成绩记录文件!\n\n");return 0;
}
return 1;
}
int main(void)
{
void record(void); //成绩录入
void research(void); //成绩查询
void putchievement(void); //成绩输出
void statistic(void); //成绩统计
char a,a1;
printf("\n\t\t ********欢迎使用本系统******** \n");
printf("\t\t\t 作者:永久指针\n");
while(1)
{
printf("\n\t1.成绩录入 ");
printf("\t\t\t\t 2.成绩查询\n");
printf("\t3.成绩统计");
printf("\t\t\t\t 4.成绩输出\n");
printf("\t5.清理屏幕");
printf("\t\t\t\t 6.系统退出\n");
printf("\t\t\t 请您输入:");
while(1)
{
while((a=getch())!='\r')
{
if(isprint(a))
{
putchar(a);
putchar('\b');
}
a1=a;
}
if(a1=='1'||a1=='2'||a1=='3'||a1=='4'||a1=='5'||a1=='6')
{
putchar('\n');
break;
}
else printf("\n\t\t\t 输入错误,请重新输入:");
}
switch(a1)
{
case '1':record(); while(getchar()!='\n');break;
case '2':research(); break;
case '3':statistic();break;
case '4':putchievement();break;
case '5':system("cls");break;
case '6':exit(0);
}
}
return 0;
}
void record(void)
{
int subjects=0,total=0;
char a,a1;
printf("1.重新录入。2.继续录入。\n请输入:");
while(1)
{
while((a=getch())!='\r')
{
if(isprint(a))
{
putchar(a);
putchar('\b');
}
a1=a;
}
if(a1=='1'||a1=='2')
{
putchar('\n');
break;
}
else printf("\n\t\t\t 输入错误,请重新输入:");
}
char file[30];
FILE *fp;
if('1'==a1)
{
printf("请您输入文件名和路径(如输入错误或1则默认d:\\chengji.txt):");
scanf("%s",file);
if((fp=fopen(file,"w"))==NULL||strcmp(file,"1")==0) //这里要大括号!
{
printf("文件名和路径已经默认。\n\n");
fp=fopen("d:\\chengji.txt","w");
}
fprintf(fp,"\t\t\t ***********成绩统计表***********\n");
fprintf(fp,"NUMBER NAME SEX");
char discipline[25];//用来记录科目。
printf("请您依次输入要录入的成绩科目(如C_language Chinese,当输入“-”时表输入结束。):\n");
while(1)
{
scanf("%24s",discipline);
if(strcmp(discipline,"-")!=0) //判断科目输入是否结束。
fprintf(fp,"%16s",discipline);//在文件中相应的打印出来。
else
{
fprintf(fp," average total\n");//再在科目后面加上平均分和总分。
printf("您已经输入完毕!\n");
break;
}
}
}
else
{
while(1)
{
printf("请您输入文件名和路径(如输入错误或1则默认d:\\chengji.txt):");
scanf("%s",file);
if((fp=fopen(file,"r+"))==NULL||strcmp(file,"1")==0)
{
printf("文件名和路径已经默认。\n\n");
fp=fopen("d:\\chengji.txt","r+");
}
if(judgefile(fp))//调用函数判断文件是否是上次录入的文件。
break;
}
}
subjects=subject(fp); //调用函数得到文件中的科目数。
fseek(fp,0L,2); //把文件指针移动到文件开头。
struct student *head1;
struct student *p1,*p2;
head1=p1=(struct student *)malloc(LEN1);
int score;//用来记录分数。
printf("请您依次输入学生的学号,姓名,性别(m或w)和各科的成绩(当学号为“-”时表输入结束。):\n");
while(1)
{
total=0;
scanf("%s",p1->num); //输入学号。
if(strcmp(p1->num,"-")!=0) //判断是否输入结束。
{
scanf("%s%s",p1->name,p1->sex); //输入姓名和性别。
fprintf(fp,"%-12s%-12s%-7s ",p1->num,p1->name,p1->sex);
int i=subjects;
while(1)
{
if(i>0)
{
i--;
scanf("%d",&score); //录入该生分数。
total+=score; //求该生的总分。
fprintf(fp,"%-12d",score);
}
else
{
fprintf(fp,"%-12.2f%-12d\n",(float)total/subjects,total); //求平均分,再在文件中打印平均分和总分。
break;
}
}
p2=(struct student *)malloc(LEN1);
p1->next=p2;
p1=p2;
}
else
{
p1->next=NULL;
free(head1);
printf("您已经输入完毕!\n");
fclose(fp);
break;
}
}
}
void research(void)
{
int subjects,stringnum=0,flag,flag1=0;
char p='0',p1,file[50];//用于记录路径和文件名。
FILE *fp;
while(1)
{
printf("请您输入上次保存的文件路径和文件名(如输入错误或1则表示默认d:\\chengji.txt):");
scanf("%50s",file);
while(getchar()!='\n');//过滤多余的字符流。
if((fp=fopen(file,"r"))==NULL||strcmp(file,"1")==0)
{
printf("文件名和路径已经默认。\n");
fp=fopen("d:\\chengji.txt","r");
}
if(judgefile(fp))//调用函数判断文件是否是上次录入的文件。
break;
}
subjects=subject(fp);
rewind(fp);
char filestring[20],getnumorname[20];
printf("\n请您选择查询方式:\n");
printf("按学号查找请输入1,按姓名查找请输入2,退出请输入其他键.\n");
printf("请输入:");
p=getch();
do
{
p1=p;
if(isprint(p))
{
putchar(p);
putchar('\b');
}
}while((p=getch())!='\r');
int flag2;//用于控制下面输出.
if('1'==p1)
{
putchar('\n');
flag2=0;
while(1)
{
int q=-1;//下面有用。
flag=0;//通过它的值来判断在文件中是否有此人。
stringnum=0;//记录在文件中已经查询了的字符串数。
flag2++;
if(1==flag2)
printf("请您输入要查询的学号(退出请输入“-”):\n");//输入要查询的学号。
while(q<20)
{
q++;
if((getnumorname[q]=getch())!='\r')
{
if(0==q) // 把"请您输入要查询的学号(退出请输入“-”):"或"查无此人,请继续或输入'-'退出:"覆盖掉。
{
putchar('\r');
printf(" ");
putchar('\r');
}
putchar(getnumorname[q]);
if(getnumorname[q]==8)
{
putchar(' ');
putchar(8);
q-=2;
if(q<-1)
q=-1;
}
}
else break;
}
getnumorname[q]='\0';
putchar('\r');
if(strcmp(getnumorname,"-")==0)//判断是否查询结束。
return;
fseek(fp,43L,0);//滤过字符串***********成绩统计表***********,以免filestring定得太大。
while(!feof(fp))
{
fscanf(fp,"%s",filestring);
stringnum++;
if(1==flag2&&stringnum>0&&stringnum
printf("%-12s",filestring);
if(stringnum==subjects+5) printf("\n");
}
if(stringnum>0&&stringnum
{
printf("%-12s",filestring);
if(stringnum==subjects+5) printf("\n");
}
if((stringnum-1)%(subjects+5)==0&&strcmp(filestring,getnumorname)==0) //找到该生的条件。
{
flag=1;//使值为1,表明存在该生。
flag1++;//记录使用者查询成功的次数。
for(int b=subjects+5;b>0;b--) //若找到则输出该生的信息。
{
printf("%-12s ",filestring);
if(b!=1)
{
fscanf(fp,"%s",filestring);
stringnum++;
}
}
printf("\n");
break;
}
else continue; //找不到则继续。
}
if(flag==0)
printf("查无此人,请继续或退出:");
}
}
else if(p1=='2')
{
char getnum[26];//用于记录文件中的学号。
putchar('\n');
flag=0;
flag2=0;
while(1)
{
int q=-1;//下面有用。
flag=0;//通过它的值来判断在文件中是否有此人。
stringnum=0;//记录在文件中已经查询了的字符串数。
flag2++;
if(1==flag2)
printf("请您输入要查询的姓名(退出请输入“-”):\n");
while(q<20)
{
q++;
if((getnumorname[q]=getch())!='\r')
{
if(0==q) // 把"请您输入要查询的学号(退出请输入“-”):"或"查无此人,请继续或输入'-'退出:"覆盖掉。
{
putchar('\r');
printf(" ");
putchar('\r');
}
putchar(getnumorname[q]);
if(getnumorname[q]==8)
{
putchar(' ');
putchar(8);
q-=2;
if(q<-1)
q=-1;
}
}
else break;
}
getnumorname[q]='\0';
putchar('\r');
if(strcmp(getnumorname,"-")==0)//判断是否查询结束。
return;
fseek(fp,43L,0); //滤过字符串***********成绩统计表***********,以免num定的太大。
while(!feof(fp))
{
fscanf(fp,"%s",filestring);
stringnum++;
if(1==flag2&&stringnum>0&&stringnum
printf("%-15s",filestring);
if(stringnum==subjects+5) printf("\n");
}
if(stringnum>0&&stringnum
{
printf("%-15s",filestring);
if(stringnum==subjects+5)
printf("\n");
}
if(stringnum%(subjects+5)==1&&stringnum>(subjects+5))
strcpy(getnum,filestring);
if((stringnum-2)%(subjects+5)==0&&strcmp(filestring,getnumorname)==0)//有此人的条件。
{
flag=1;//使值为1,表明存在该生。
flag1++;//记录使用者查询成功的次数。
for(int b=subjects+4;b>0;b--)
{
if(b==subjects+4)
printf("%-15s",getnum);
printf("%-15s",filestring);
if(b!=1)
{
fscanf(fp,"%s",filestring);
stringnum++;
}
}
printf("\n");
}
else continue;
}
if(flag==0)
printf("查无此人,请继续或退出:");
}
}
else return;
}
void statistic(void)
{
char file[30];
char subjectnum[4],a;
int b;
FILE *fp;
while(1)
{
printf("请您输入上次保存的文件路径和文件名(如输入错误或1则表示默认d:\\chengji.txt):");
scanf("%s",file);
while(getchar()!='\n');
if((fp=fopen(file,"r"))==NULL||strcmp(file,"1")==0)
{
printf("文件名和路径已经默认。\n");
fp=fopen("d:\\chengji.txt","r");
}
if(judgefile(fp))//调用函数判断文件是否是上次录入的文件。
break;
}
char filestring[25],*p; //num不能小于"***********成绩统计表***********"的长度,否则输出"***********成绩统计表**********************成绩统计表***********".
int num1[3][20]={0};
int i,stringnum=0,q,j,num2,excellentmark,passmark;
p=filestring;
i=subject(fp); //统计文件的科目书数。
rewind(fp);
printf("请您输入优秀分数线:");
while(1)
{
b=0;
while((a=getch())!='\r')
{
if(isdigit(a)&&(b<3))
{
putchar(a);
subjectnum[b]=a;
b++;
}
if(8==a)
{
if(--b>=0)
{putchar('\b');putchar(' ');putchar('\b');}
else b++;
}
}
subjectnum[b]='\0';
if((excellentmark=toint(subjectnum))<=0)
printf("\n输入错误,请重新输入:");
else {putchar('\n'); break;}
}
printf("请您输入及格分数线:");
while(1)
{
b=0;
while((a=getch())!='\r')
{
if(isdigit(a)&&(b<3))
{
putchar(a);
subjectnum[b]=a;
b++;
}
if(8==a)
{
if(--b>=0)
{putchar('\b');putchar(' ');putchar('\b');}
else b++;
}
}
subjectnum[b]='\0';
if((passmark=toint(subjectnum))<=0||passmark>excellentmark)
printf("\n输入错误,请重新输入:");
else {putchar('\n'); break;}
}
fseek(fp,43L,0);//滤过字符串***********成绩统计表***********,以免num定的太大。
while(!feof(fp))
{
stringnum++;
if(stringnum>3&&stringnum<4+i)
{
fscanf(fp,"%s",filestring);
if(stringnum==4)
printf("\t ");
printf("%15s",filestring);
if(stringnum==i+3)
printf("\n");
}
else if(stringnum%(i+5)>3&&stringnum%(i+5)<(i+4))
{
fscanf(fp,"%d",&num2);
if(num2>=excellentmark)
num1[0][(stringnum%(5+i))-4]++;
else if(num2>=passmark)
num1[1][(stringnum%(5+i))-4]++;
else
num1[2][(stringnum%(5+i))-4]++;
}
else fscanf(fp,"%s",filestring);
}
for(j=0;j<3;j++)
{
switch(j)
{
case 0: printf("优秀段 (%d~ ) ",excellentmark);break;
case 1: printf("及格段 (%d~%d) ",excellentmark,passmark);break;
case 2: printf("不及格段(0 ~%d) ",passmark);break;
}
for(q=0;q printf(" %-12d",num1[j][q]);
printf("\n");
}
for(j=0;j<2;j++)
{
switch(j)
{
case 0:printf("优秀率 ");break;
case 1:printf("及格率 ");break;
}
if(j==0)
for(q=0;q {
printf(" %-4.2f%% ",100*(float)(i+5)*num1[j][q]/(stringnum-6-i));
if(q==i-1)
printf("\n");
}
if(j==1)
for(q=0;q printf(" %-4.2f%% ",100*(float)(i+5)*(num1[j][q]+num1[0][q])/(stringnum-6-i));
}
}
void putchievement(void)
{
char choice,a;
char file[60],filestr[26];
int subjectnum,flag=0,totalstudent=0;
FILE *fp;
while(1)
{
printf("请您输入上次保存的文件路径和文件名(如输入错误或1则表示默认d:\\chengji.txt):");
scanf("%60s",file);
while(getchar()!='\n');
if((fp=fopen(file,"r"))==NULL||strcmp(file,"1")==0)
{
printf("文件名和路径已经默认。\n\n");
fp=fopen("d:\\chengji.txt","r");
}
if(judgefile(fp))//调用函数判断文件是否是上次录入的文件。
break;
}
subjectnum=subject(fp);
rewind(fp);
printf("1.按学号输出\t\t 2.按总分输出\t\t 3.退出\n");
printf("请输入:");
while(1) //防一下漏洞!
{
choice='\r';
while((a=getch())!='\r')
{
if(a>48&&a<52)
{
putchar(a);
putchar('\b');
}
choice=a;
}
if(choice!='\r')
{
putchar('\n');
break;
}
}
if('3'==choice)
exit(0);
fseek(fp,43L,0); //滤过字符串***********成绩统计表***********,以免filestr定的太大。
flag=subjectnum;
while(flag-->-5) //输出“NUMBER NAME...”等项。
{
fscanf(fp,"%s",filestr);
printf("%-15s",filestr);
}
if('1'==choice)
{
flag=0;
struct row_preface
{
char studentnum[20];
long position; //用来记录读取该学号后文件指针的位置,以便到时候输出该学号后面的项。
struct row_preface *next;
};
struct row_preface *head,*p1,*p2;
int len=sizeof(struct row_preface);
head=p1=(struct row_preface *)malloc(len);
while(!feof(fp))
{
fscanf(fp,"%s",filestr);
flag++;
if(flag%(subjectnum+5)==1)
{
totalstudent++;//用于记录学生的人数。
strcpy(p1->studentnum,filestr);
p1->position=ftell(fp);
p2=(struct row_preface *)malloc(len);
p1->next=p2;
p1=p2;
}
}
p2->next=NULL;
long transition;
char storge[20];
totalstudent=totalstudent-2; //计算出统计的人数。
for(int i=totalstudent;i>1;i--)
{
p1=head;
for(int j=i;j>0;j--)
{
p2=p1->next;
if(strcmp(p1->studentnum,p2->studentnum)>0)
{
strcpy(storge,p1->studentnum);
strcpy(p1->studentnum,p2->studentnum);
strcpy(p2->studentnum,storge);
transition=p1->position;
p1->position=p2->position;
p2->position=transition;
}
p1=p2;
}
}
p1=head;
while(p1->next->next!=NULL)
{
flag=subjectnum;
p2=p1->next;
printf("\n%-15s",p1->studentnum);
fseek(fp,p1->position,0);//使指针指到文件中的该学号后面。
while((flag--)>-4) //输出学号后面的项。
{
fscanf(fp,"%s",filestr);
printf("%-15s",filestr);
}
p1=p2;
}
free(head);
}
if('2'==choice)
{
flag=0;
struct row_preface
{
int totalnum; //用来记录总分。
long position; //用来记录读取该学号前文件指针的位置,以便到时候输出该学号和后面的项。
struct row_preface *next;
};
struct row_preface *head,*p1,*p2;
int len=sizeof(struct row_preface);
head=p1=(struct row_preface *)malloc(len);
p1->position=ftell(fp);
while(!feof(fp))
{
flag++;
if(flag%(subjectnum+5)!=0)
fscanf(fp,"%s",filestr);
if(flag%(subjectnum+5)==0)
{
totalstudent++;//用于记录学生的人数。
fscanf(fp,"%d",&p1->totalnum);
p2=(struct row_preface *)malloc(len);
p1->next=p2;
p2->position=ftell(fp);
p1=p2;
}
}
p2->next=NULL;
long transition;
totalstudent=totalstudent-2; //计算出统计的人数。
for(int i=totalstudent;i>1;i--)
{
p1=head;
for(int j=i;j>0;j--)
{
p2=p1->next;
if(p1->totalnum
{
transition=p1->totalnum; //交换总分。
p1->totalnum=p2->totalnum;
p2->totalnum=transition;
transition=p1->position; //交换指针位置。
p1->position=p2->position;
p2->position=transition;
}
p1=p2;
}
}
flag=subjectnum;
putchar('\n');
p1=head;
while(p1->next->next!=NULL)
{
p2=p1->next;
fseek(fp,p1->position,0);//使指针指到文件中的该学号前面。
flag=subjectnum+5;
while(flag--)
{
fscanf(fp,"%s",filestr);
printf("%-15s",filestr);
}
putchar('\n');
p1=p2;
}
free(head);
}
}
楼上还在编程,太麻烦了吧,有现成的软件下载哦
学生成绩管理系统系统V3.0
http://zjtele3.skycn.com/down/wscjgl.zip(请用迅雷下载)
是作者在长期教育教学过程管理中实践与总结的成果。历经Foxplus至VF的开发平台变迁升级(1998-2002),软件自身也得以不断完善和发展。V3.0版具备从建立、分析(用户自由设定分析标准)、管理的全过程管理,引入许多全新管理概念,使得其界面更精彩、功能更强大!
第一种
include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;
void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j{
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}
void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}
fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>shuru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>xianshi 6>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}
}
第二种
平均分我的没有,只有一个计算三门成绩总分的.你可以参考.
// student.h: interface for the student class.
//
//////////////////////////////////////////////////////////////////////
#include "score.h"
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_STUDENT_H__7F838617_8CEB_4640_8740_EA0EFCE6BADE__INCLUDED_)
#define AFX_STUDENT_H__7F838617_8CEB_4640_8740_EA0EFCE6BADE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class student
{
public:
student();
virtual ~student();
int getNum();
float sum();
void print();
void modify(char* r,char* n,float m,float e,float c);
private:
char number[20];
char name[30];
score ascore;
};
#endif // !defined(AFX_STUDENT_H__7F838617_8CEB_4640_8740_EA0EFCE6BADE__INCLUDED_)
// student.cpp: implementation of the student class.
//
//////////////////////////////////////////////////////////////////////
#include
#include
#include
#include "student.h"
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
student::student()
{
}
student::~student()
{
}
void student::print()
{
cout<
}
void student::modify(char* r,char* n,float m,float e,float c)
{
strcpy(number,r);
strcpy(name,n);
ascore.modify(m,e,c);
}
float student::sum()
{
float a;// score.h: interface for the score class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SCORE_H__52859404_C529_4188_9FCD_161B7F88FEB3__INCLUDED_)
#define AFX_SCORE_H__52859404_C529_4188_9FCD_161B7F88FEB3__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class score
{
public:
score(float c=0.0,float m=0.0,float e=0.0);
virtual ~score();
float sum();
void print();
void modify(float m,float e,float c);
private:
float computer;
float english;
float mathematics;
static float total;
};
#endif // !defined(AFX_SCORE_H__52859404_C529_4188_9FCD_161B7F88FEB3__INCLUDED_)
// score.cpp: implementation of the score class.
//
//////////////////////////////////////////////////////////////////////
#include
#include
#include "score.h"
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
score::score(float c,float m,float e)
{
computer = c;
mathematics = m;
english = e;
total = computer + english +mathematics;
}
score::~score()
{
}
float score::total = 0;
float score::sum()
{
total = mathematics+english+computer;
return total;
}
void score::print()
{
cout<
void score::modify(float m,float e,float c)
{
mathematics = m;
english = e;
computer = c;
}
#include
#include
#include "score.h"
#include "student.h"
using namespace std;
const int maxSize = 50;
int main()
{
student stu[maxSize];
char number[20];
char name[30];
float tmp_sum;
float math,eng,comp;
int total;
do
{
cout<<"please input the number of students: ";
cin>>total;
if (total>maxSize || total<1)
cout<<"ERROR: 0
while (total<1 || total>maxSize);
cout<<"please input the student's message:(number name mathematics english computer)"<
cout<<"学生"<cin>>number>>name>>math>>eng>>comp;
stu[i].modify(number,name,math,eng,comp);
}
cout<<"***************************************************"<
stu[i].print();
cout<
cout<<"***************************************************"<
}
/* cin>>reg_num;
bool found = false;
for (i=0; i
if(stu[i].getNum() == *reg_num)
{
cout<
cout<
break;
}
if (!found)
cout<<"没这个人!"<
*/
a = ascore.sum();
return a;
}