求一个vc++学生成绩管理系统程序

2024年11月21日 00:25
有1个网友回答
网友(1):

#include
#include
typedef struct count{ /*保存记录条数结构体*/
char name[10];
int num;
}count;
typedef struct st{
char name[10];
long Number;
int Math;
int C;
int Amount;
}st;
st record[8];
count num[1];
char filename[10]={"0"};
char filename2[10]={"0"};
int Inputnum[8];

void MainMenu(){ /*主菜单*/
printf("\n\t\t\t\t* * * * * * * * * *\n");
printf("\t\t\t\t* 主菜单 *\n");
printf("\t\t\t\t* 1. 新建数据 *\n");
printf("\t\t\t\t* 2. 添加数据 *\n");
printf("\t\t\t\t* 3. 删除数据 *\n");
printf("\t\t\t\t* 4. 排序 *\n");
printf("\t\t\t\t* 5. 查询 *\n");
printf("\t\t\t\t* 6. 退出 *\n");
printf("\t\t\t\t* * * * * * * * * *\n");
}
void DelMenu(){ /*删除菜单*/
printf("\n\t\t\t\t* * * * * * * * * * * *\n");
printf("\t\t\t\t* 删除菜单 *\n");
printf("\t\t\t\t* 1. 学号查询删除 *\n");
printf("\t\t\t\t* 2. 返回到上级菜单 *\n");
printf("\t\t\t\t* * * * * * * * * * * *\n");
}
void RankingMenu(){ /*排序菜单*/
printf("\n\t\t\t\t* * * * * * * * * * * *\n");
printf("\t\t\t\t* 排序菜单 *\n");
printf("\t\t\t\t* 1. 数学成绩排序 *\n");
printf("\t\t\t\t* 2. C语言成绩排序 *\n");
printf("\t\t\t\t* 3. 总分排序 *\n");
printf("\t\t\t\t* 4. 返回主菜单 *\n");
printf("\t\t\t\t* * * * * * * * * * * *\n");
}
void InquireMenu(){ /*查讯菜单*/
printf("\n\t\t\t\t* * * * * * * * * * * *\n");
printf("\t\t\t\t* 查讯菜单 *\n");
printf("\t\t\t\t* 1. 学号查讯 *\n");
printf("\t\t\t\t* 2. 姓名查讯 *\n");
printf("\t\t\t\t* 3. 数学成绩查讯 *\n");
printf("\t\t\t\t* 4. 程序设计成绩查询 *\n");
printf("\t\t\t\t* 5. 总分查讯 *\n");
printf("\t\t\t\t* 6. 总分查询 *\n");
printf("\t\t\t\t* * * * * * * * * * * *\n");
}
char Inputfilename(){ /*输入文件名同时产生付本文件名*/
char str2[]={"B"};
printf("** 请输入文件名 ** : ");
scanf("%s",filename);
getchar();
strcpy(filename2,filename);
strcat(filename2,str2);
}
FILE *readfile(){ /*读取文档*/
FILE *fp1;
if((fp1=fopen(filename,"rb"))==NULL)
{printf("\n文件读取错误!!\n");
fclose(fp1);
}
return(fp1);
}
FILE *foundfile(){ /*新建文档*/
FILE *fp1;
if((fp1=fopen(filename,"wb"))==NULL)
{printf("\n文件创建错误!!\n");
fclose(fp1);
}
return(fp1);
}
FILE *savefile(){ /*追加文档*/
FILE *fp1;
if((fp1=fopen(filename,"ab"))==NULL)
{printf("\n文件追加错误!!\n");
fclose(fp1);
}
return(fp1);
}
int InputSave(){ /*添加数据 */
int i=0,j;
char ch='y';
while(ch!='w')
{i=i+1;
printf("\n** 请输入姓名(字符型) ** :");
scanf("%s",record[i].name);
Loop1: printf("\n** 请输入学号(长整型) ** :");
scanf("%ld",&record[i].Number);
if(i!=1)
for(j=1;jif(record[i].Number==record[j].Number)
{printf("\n\t警告! 输入了二个同样的学号! 第%d条和第%d学号相同!\n",i,j);
printf("\n\t请重新输入!\n");
goto Loop1;
}
Loop2: printf("\n** 请输入数学成绩(整型) ** :");
scanf("%d",&record[i].Math);
if(record[i].Math>100||record[i].Math<0)
{printf("\n\t输入的分数不服合实际要求! 请重新录入!\n");
goto Loop2;
}
Loop3: printf("\n** 请输入C语言成绩(整型) ** :");
scanf("%d",&record[i].C);
if(record[i].C>100||record[i].C<0)
{printf("\n\t输入的分数不服合实际要求! 请重新录入!\n");
goto Loop3;
}
record[i].Amount=record[i].Math+record[i].C;
printf(" \n'w'=结束录入 's'=重新录入此条记录 'n'=下一条 : ");
getchar(); /*吃掉上一个回车符*/
if((ch=getchar())=='s')
i=i-1;
}
return(i);
}
/*
void ReadComputer(int i,FILE *fp1){ (文本方式)数据写入机器
int j;
for(j=1;jfscanf(fp1,"%s,%ld,%d,%d,%d",record[j].name,&record[j].Number,&record[j].Math,&record[j].C,&record[j].Amount);
}
void SaveFile(int i,FILE *fp1){ (文本方式)数据写到文件中
int j;
for(j=1;jfprintf(fp1,"%s,%ld,%d,%d,%d",record[j].name,record[j].Number,record[j].Math,record[j].C,record[j].Amount);
}
*/

void ReadComputer2(int i,FILE *fp1){ /*(2方式)数据写入机器*/
int j;
for(j=1;jif((fread(&record[j],sizeof(struct st),1,fp1))!=1)
{printf("\n主文件数据读取错误! \n");
fclose(fp1);
}
}

void SaveFile2(int i,FILE *fp1){ /*(2方式)数据写到文件中*/
int j;
for(j=1;jif((fwrite(&record[j],sizeof(struct st),1,fp1))!=1)
{printf("\n主文件数据写入错误! \n");
fclose(fp1);
}
}
/* ************************************************************ *********************************************************** */
FILE *readfile2()
{ /*读文件付本*/
FILE *fp1;
if((fp1=fopen(filename2,"rb"))==NULL)
{printf("\n付本文件读取错误!\n");
fclose(fp1);
}
return(fp1);
}
FILE *foundfile2(){ /*新建文件付本*/
FILE *fp1;
if((fp1=fopen(filename2,"wb"))==NULL)
{printf("\n付本文件创建错误!\n");
fclose(fp1);
}
return(fp1);
}
FILE *savefile2(){ /*追加文件付本*/
FILE *fp1;
if((fp1=fopen(filename2,"ab"))==NULL)
{printf("\n付本文件追加错误!\n");
fclose(fp1);
}
return(fp1);
}
/*
void Additive2(int i,FILE *fp1){ 数据与入付本文件(文本方式)
int j;
char str2={"0"};
if(strcmp(filenameF,str2)!=0)
strcpy(num[0].name,filenameF);
else
strcpy(num[0].name,filenameA);
num[0].num=i;
fprintf(fp1,"%s,%d",num[0].name,num[0].num);
}
int ReadComputer2(FILE *fp1){ 读出付本中的数据(文本方式)
int j,k;
fscanf(fp1,"%s,%d",num[0].name,&num[0].num);
k=num[0].num;
return(k);
}
*/

void Additive2Two(int i,FILE *fp1){ /*数据写入付本文件(二进制方式)*/
char str2[]={"0"};
if(strcmp(filename2,str2)!=0)
strcpy(num[0].name,filename2);
else
strcpy(num[0].name,filename2);
num[0].num=i;
if((fwrite(&num[0],sizeof(struct count),1,fp1))!=1)
{printf("\n付本文件数据写入错误! \n");
fclose(fp1);
}
}
int ReadComputer2Two(FILE *fp1){ /*读出付本中的数据(二进制方式)*/
int j;
if((fread(&num[0],sizeof(struct count),1,fp1))!=1)
{printf("\n付本文件数据读取错误! \n");
fclose(fp1);
}
j=num[0].num;
return(j);
}
/* ************************************************************ *********************************************************** */

void Num_inquire(){ /*学号查询*/
int num,j,time;
FILE *fp1,*fp2;
fp1=readfile(); /*读取文档*/
fp2=readfile2(); /*(开打方式'读'**'引用读文件名')读文件付本*/
time=ReadComputer2Two(fp2); /*读出付本中的数据(二进制方式)*/
ReadComputer2(time,fp1); /*(2方式)数据写入机器*/
fclose(fp1);fclose(fp2);
printf("输入学号:");
scanf("%ld",&num);
/*getchar();*/
for(j=1;j{if(record[j].Number==num)
printf("\nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3d\n",record[j].name,record[j].Number,record[j].Math,record[j].C,record[j].Amount);
}
}

void Name_inquire(){ /*姓名查询*/
int j,time;
char Name[10];
FILE *fp1,*fp2;
fp1=readfile();
fp2=readfile2(); /*(开打方式'读'**'引用读文件名')读文件付本*/
time=ReadComputer2Two(fp2); /*读出付本中的数据(二进制方式)*/
ReadComputer2(time,fp1); /*(2方式)数据写入机器*/
fclose(fp1);fclose(fp2);
printf("输入姓名:");
scanf("%s",Name);
/*getchar();*/
for(j=1;j{if(strcmp(Name,record[j].name)==0)
printf("\nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3d\n",record[j].name,record[j].Number,record[j].Math,record[j].C,record[j].Amount);
}
}

void Math_inquire(){ /*数学查询*/
int Math,j,time;
FILE *fp1,*fp2;
fp1=readfile();
fp2=readfile2(); /*(开打方式'读'**'引用读文件名')读文件付本*/
time=ReadComputer2Two(fp2); /*读出付本中的数据(二进制方式)*/
ReadComputer2(time,fp1); /*(2方式)数据写入机器*/
fclose(fp1);fclose(fp2);
printf("输入数学成绩:");
scanf("%d",&Math);
/*getchar();*/
for(j=1;j {if(record[j].Math>=Math)
printf("\nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3d\n",record[j].name,record[j].Number,record[j].Math,record[j].C,record[j].Amount);
}
}

void C_inquire(){ /*C查询*/
int C,j,time;
FILE *fp1,*fp2;
fp1=readfile();
fp2=readfile2(); /*(开打方式'读'**'引用读文件名')读文件付本*/
time=ReadComputer2Two(fp2); /*读出付本中的数据(二进制方式)*/
ReadComputer2(time,fp1); /*(2方式)数据写入机器*/
fclose(fp1);fclose(fp2);
printf("输入C语言成绩:");
scanf("%d",&C);
/*getchar();*/
for(j=1;j {if(record[j].C>=C)
printf("\nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3d\n",record[j].name,record[j].Number,record[j].Math,record[j].C,record[j].Amount);
}
}

void Amount_inquire(){ /*总分查询*/
int Amount,j,time;
FILE *fp1,*fp2;
fp1=readfile();
fp2=readfile2(); /*(开打方式'读'**'引用读文件名')读文件付本*/
time=ReadComputer2Two(fp2); /*读出付本中的数据(二进制方式)*/
ReadComputer2(time,fp1); /*(2方式)数据写入机器*/
fclose(fp1);fclose(fp2);
printf("输入总分:");
scanf("%d",&Amount);
/*getchar();*/
for(j=1;j {if(record[j].Amount>=Amount)
printf("\nName:%-10s Num:%3ld Math:%3d C:%3d Amount:%3d\n",record[j].name,record[j].Number,record[j].Math,record[j].C,record[j].Amount);
}
}
/* ************************************************************ *********************************************************** */

void Num_inquire_Del(){ /*学号查询删除*/
char ch;
int num,j,k,time;
FILE *fp1,*fp2;
fp1=readfile(); /*读取文档*/
fp2=readfile2(); /*读文件付本*/
time=ReadComputer2Two(fp2); /*读出付本中的数据(二进制方式)*/
ReadComputer2(time,fp1); /*(2方式)数据写入机器*/
fclose(fp1);fclose(fp2);
//这是前319行,还有三百多行,你的邮箱是多少,我发给你,这里字数有限制,写不下