📄 学生成绩管理系统2.0修改版.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
/*********************************************************************************************************************/
/*********************************************************************************************************************/
int ok0(int x) //这个函数是用于界面的输入
{
int l;
do
{
system("cls");
printf ("\t\t\t ********************\n"
"\t\t\t ** 学生信息管理 **\n"
"\t\t\t ********************\n"
"\n"
"\n"
"\t ┏━━━━━━━━━━━━━━━━━━━━━━━┓\n"
"\t ┃ 1.录入学生基本信息 ┃\n"
"\t ┃ 2.录入成绩信息 ┃\n"
"\t ┃┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┃\n"
"\t ┃ 3.修改学生成绩 ┃\n"
"\t ┃┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┃\n"
"\t ┃ 4.删除学生的全部信息 ┃\n"
"\t ┃┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┃\n"
"\t ┃ 5.按[班级]查询学生的信息 ┃\n"
"\t ┃ 6.按[班级]查询成绩 ┃\n"
"\t ┃ 7.显示通过考试的学生信息 ┃\n"
"\t ┃┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┃\n"
"\t ┃ 8.退出 ┃\n"
"\t ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n"
"\n"
"\t\t\t\t\t\t\t\t代码编写:刘伟\n"
"\t\t\t\t\t\t\t\t界面美工:王帅\n"
"\t\t\t\t\t\t\t\t软件测试:王帅\n"
"\n");
printf("请按数字键选择您要使用的功能:");
scanf("%d",&l);
fflush(stdin);
}while(l<1||l>8);
return(l);
getch();
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
int ip(char x[6]) //这个函数实现查询最大学号
{
int q=0;
struct t //定义结构体存文件的资料
{
char a1[6];
int a2;
char a3[20];
float a4;
}a;
FILE *fp1;
if((fp1=fopen("info.dat","rb"))==NULL)
{system("cls");
printf("很抱歉,没有找到您所需要的文件...\n"
"请按任意键重新选择您所需要使用的功能...");
getch();
return;
}
while(fread(&a,sizeof(struct t),1,fp1)==1)
if(strcmp(a.a1,x)==0) //循环打开文件结构体记录次数
{q++;}
q++;
fclose(fp1);
return(q); //不匹配等于1
}
void ok1(int x) //这函数用于
{ int n;
struct students
{
char banji[6]; //班级
int id; //学号
char name[20]; //姓名
float chengji; //成绩
}a0; //定义一个结构体
system("cls");
printf(" 录入学生基本信息\n");
do
{
FILE *fp;
if((fp=fopen("info.dat","a+b"))==NULL)
{
system("cls");
printf("很抱歉,没有找到您所需要的文件...\n"
"请按任意键重新选择您所需要使用的功能...");
getch();
return;
}
printf("\n");
printf("请输入学生基本信息\n");
printf(" 学生所在班级名称:");
scanf("%5s",a0.banji);
a0.id=ip(a0.banji);
fflush(stdin);
printf(" 班内学号:%d\n",a0.id);//函数调用计算最大学号
printf(" 学生姓名:");
scanf("%19s",a0.name);
a0.chengji=0.0;
fwrite(&a0,sizeof(struct students),1,fp);
fclose(fp);
fflush(stdin);
printf("继续输入吗?(Y/N)");
n=getchar();fflush(stdin);
}while(n=='y'||n=='Y'); //判断是否继续输入
printf("请您按任意键返回上一级菜单继续使用其他功能......\n");
getch();
return;
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void xr(char x[6],int y,float z) //用于写入info.dat文件的平均分
{
struct i //定义结构体储存文件内容
{
char a1[6];
int a2;
char a3[20];
float a4;
}a;
FILE *fp3;
if ((fp3=fopen("info.dat","rb+"))==NULL) //打开score.dat文件
{system("cls");
printf("很抱歉,没有找到您所需要的文件...\n"
"请按任意键重新选择您所需要使用的功能...");
getch();
return;}
while(fread(&a,sizeof(struct i),1,fp3)==1) //循环读出文件结构体
{
if((strcmp(a.a1,x)==0)&&(a.a2==y)) //写入条件
{
a.a4=z;
fseek(fp3,-36,1);
fwrite(&a,sizeof(struct i),1,fp3);break; //写入平均值
}
}
fclose(fp3); //关闭文件
}
float pingjun(float x,float y,float z) //3个成绩求平均分
{
x=x+y+z;
x=x/3;
return(x);
}
int xy(char x[6],int y) //这个函数主要实现查询输入的学号的成绩是否存在score.dat的文件中
{ int w=0,e=0; //w没有查询到的返回变量,e查询到的返回变量
struct i //定义结构体储存文件内容
{
char a1[6];
int a2;
float c;
float sql;
float vb;
}a;
FILE *fp2;
if ((fp2=fopen("score.dat","rb"))==NULL) //打开score.dat文件
{system("cls");
printf("很抱歉,没有找到您所需要的文件...\n"
"请按任意键重新选择您所需要使用的功能...");
getch();
return;}
while(fread(&a,sizeof(struct i),1,fp2)==1) //循环读出文件结构体
if((strcmp(a.a1,x)==0)&&(a.a2==y)) //查询条件
{e++;return(e);} //返回1
fclose(fp2); //关闭文件
return(w--); //返回非1
}
int xp(char x[6],int y) //这个函数主要实现查询输入的班级和学号是否存在info.dat的文件中
{ int e=0; //e查询到的返回变量
struct i //定义结构体储存文件内容
{
char a1[6];
int a2;
char a3[20];
float a4;
}a;
FILE *fp1;
if((fp1=fopen("info.dat","rb"))==NULL) //打开文件
{system("cls");
printf("很抱歉,没有找到您所需要的文件...\n"
"请按任意键重新选择您所需要使用的功能...");
getch();
return;}
while(fread(&a,sizeof(struct i),1,fp1)==1) //循环读出文件结构体
if((strcmp(a.a1,x)==0)&&(a.a2==y)) //查询条件
{e++;return(e);} //返回1
fclose(fp1); //关闭文件
return(e--);
}
void ok2(int x)
{ char ay; //ay存是否继续输入
float an; //an存平均分
int bo=0,bb=0; //bo存查info.dat的返回变量,bb存score.dat的返回变量
struct a1 //定义score.dat结构体
{
char banji[6];
int id;
float c;
float sql;
float vb;
}xd;
FILE *fq;
if ((fq=fopen("score.dat","a+b"))==NULL)//打开score.dat文件
{system("cls");
printf("很抱歉,没有找到您所需要的文件...\n"
"请按任意键重新选择您所需要使用的功能...");
getch();
return;}
system("cls");
printf(" 录入学生成绩\n\n");
printf("请您输入班级名称:");
scanf("%5s",xd.banji);
do{
printf(" 请您输入学号:");
scanf("%d",&xd.id);
bo=xp(xd.banji,xd.id); //函数调用查info.dat
bb=xy(xd.banji,xd.id); //函数调用查score.dat
fflush(stdin);
if(bo!=1||bb==1)
{
printf("info.dat文件中没有学号为%d的学生信息,或者score.dat文件中已经存在该学号学生的成绩\n",xd.id);
printf("请您按任意键返回上一级菜单继续使用其他功能...");
getch();
return;
}
printf("\n");
printf(" 请您输入C语言的成绩:");
scanf("%f",&xd.c);
if(xd.c<0||xd.c>100)
{
printf("您的输入有错误!!!\n请您按任意键返回上一级菜单继续使用其他功能...");
getch();return;
}
printf(" 请您输入SQL语言的成绩:");
scanf("%f",&xd.sql);
if(xd.sql<0||xd.sql>100)
{
printf("您的输入有错误!!!\n请您按任意键返回上一级菜单继续使用其他功能...");
getch();return;
}
printf(" 请您输入VB语言的成绩:");
scanf("%f",&xd.vb);
if(xd.vb<0||xd.vb>100)
{
printf("您的输入有错误!!!\n请您按任意键返回上一级菜单继续使用其他功能...");
getch();return;
}
fwrite(&xd,sizeof(struct a1),1,fq); //写入score.dat中
//关闭文件
an=pingjun(xd.c,xd.sql,xd.vb); //函数调用求平均分
xr(xd.banji,xd.id,an); //函数调用写平均分
printf("继续输入吗?(Y/N):");fflush(stdin);
ay=getchar();
}while(ay=='y'||ay=='Y');
fclose(fq); //getch();
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void p3(char x[6],int y,float z) //用于写入info.dat文件的平均分
{
struct i //定义结构体储存文件内容
{
char a1[6];
int a2;
char a3[20];
float a4;
}a;
FILE *fp3;
if ((fp3=fopen("info.dat","rb+"))==NULL) //打开score.dat文件
{system("cls");
printf("很抱歉,没有找到您所需要的文件...\n"
"请按任意键重新选择您所需要使用的功能...");
getch();
return;}
while(fread(&a,sizeof(struct i),1,fp3)==1) //循环读出文件结构体
{
if((strcmp(a.a1,x)==0)&&(a.a2==y)) //写入条件
{
a.a4=z;
fseek(fp3,-36,1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -