|
|
#include<stdio.h>
|
|
|
#include"math.h"
|
|
|
#include"process.h"
|
|
|
#include<stdlib.h>
|
|
|
#include<string.h>
|
|
|
#include"windows.h"
|
|
|
int i,j,k,y;
|
|
|
FILE *fp;
|
|
|
struct stu
|
|
|
{
|
|
|
int xh[30];
|
|
|
char name[30];
|
|
|
float score;
|
|
|
long a;
|
|
|
}stu;
|
|
|
|
|
|
int fun();
|
|
|
void choose(); /*目录的选项*/
|
|
|
void input(); /*输入记录*/
|
|
|
void output(); /*输出记录*/
|
|
|
void modify(); /*修改记录*/
|
|
|
void lookat(); /*查询成绩*/
|
|
|
void subsection(); /*学生成绩分段*/
|
|
|
|
|
|
|
|
|
int fun() //菜单目录
|
|
|
{
|
|
|
int n;
|
|
|
system("cls");
|
|
|
printf("\n\n\t\t\t\t 成绩记录薄");
|
|
|
printf("\n\n\t\t\t");
|
|
|
for(i=0;i<33;i++)
|
|
|
printf("*");
|
|
|
printf("\n");
|
|
|
printf("\t\t\t ************菜单*************\n");
|
|
|
printf("\t\t\t* 1、创建学生的信息! \t*\n");
|
|
|
printf("\t\t\t* 2、输出所有学生的信息! \t*\n");
|
|
|
printf("\t\t\t* 3、修改成绩! \t*\n");
|
|
|
printf("\t\t\t* 4、查询! \t*\n");
|
|
|
printf("\t\t\t* 5、显示成绩分段的学生信息!\t*\n");
|
|
|
printf("\t\t\t");
|
|
|
for(i=0;i<33;i++)
|
|
|
printf("*");
|
|
|
printf("\n\n");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int main() //主函数
|
|
|
{
|
|
|
int n;
|
|
|
system("cls");
|
|
|
n=fun();
|
|
|
choose();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
void choose() //选择菜单
|
|
|
{
|
|
|
int a;
|
|
|
printf("\t\t\t\t 请输入您接下来想进行的操作\n");
|
|
|
printf("\t\t\t\t\t\t ");
|
|
|
scanf("%d",&a);
|
|
|
switch(a)
|
|
|
{
|
|
|
case 0:break;
|
|
|
case 1:input();break;
|
|
|
case 2:output();break;
|
|
|
case 3:modify();break;
|
|
|
case 4:void lookat();break;
|
|
|
case 5:subsection();break;
|
|
|
default:printf("\t\t\t\t\t无效的操作!请输入正确的操作!\n");
|
|
|
return choose();
|
|
|
}
|
|
|
printf("\t■□■□■□■□■□\n");
|
|
|
printf("\t-----*****程序已结束*****------\n");
|
|
|
printf("\t\t\t\t\t\n");
|
|
|
printf("\t\t\t\t\t\n");
|
|
|
printf("\t\t\t\t\t\n");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
void input() //(1)学生成绩信息录入函数
|
|
|
{
|
|
|
char next='y';
|
|
|
fp=fopen("out.txt","a");
|
|
|
//printf("请以0作为输入学生学号信息的结束!\n");
|
|
|
while(next!='y');
|
|
|
{
|
|
|
printf("输入学生的学号:");
|
|
|
scanf("%d",&stu.xh);
|
|
|
printf("输入学生的姓名:");
|
|
|
scanf("%s",stu.name);
|
|
|
printf("输入学生的C语言成绩:");
|
|
|
scanf("%f",&stu.score);
|
|
|
printf("输入添加成绩的时间:");
|
|
|
scanf("%ld",&stu.a);
|
|
|
fprintf(fp,"%d %-4s %.1f %ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
fflush(stdin);
|
|
|
scanf("%c",&next);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
void output() //(2)学生全部信息输出
|
|
|
{
|
|
|
if((fp=fopen("out.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("Cannot open the file!\n");
|
|
|
}
|
|
|
printf("\t\t\t全部的学生信息:\n");
|
|
|
while(fscanf(fp,"%d%s%f%ld",&stu.xh,stu.name,&stu.score,&stu.a)!=EOF)
|
|
|
{
|
|
|
printf("\t\t\t%d\t%s\t%.1f\t%ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
}
|
|
|
fclose(fp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void modify() //(3)修改学生信息函数
|
|
|
{
|
|
|
char st[30];
|
|
|
int x,num[10];
|
|
|
float nu;
|
|
|
long h;
|
|
|
k=0;
|
|
|
system("cls");
|
|
|
if((fp=fopen("out.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("Cannot open the file!\n");
|
|
|
return;
|
|
|
}
|
|
|
while(fscanf(fp,"%d%s%f%ld",&stu.xh,stu.name,&stu.score,&stu.a)!=EOF)
|
|
|
{
|
|
|
k++;
|
|
|
}
|
|
|
printf("输入1表示用学号修改,输入2表示用姓名修改!请选择:\n");
|
|
|
scanf("%d",&x);
|
|
|
if(x==1)
|
|
|
{
|
|
|
printf("请输入修改成绩人的学号:");
|
|
|
//for(i=0;i<5;i++)
|
|
|
scanf("%d",num);
|
|
|
for(i=0;i<k;i++)
|
|
|
if(num==stu.xh)
|
|
|
{
|
|
|
printf("请输入修改的成绩:\n");
|
|
|
scanf("%f",&nu);
|
|
|
stu.score=nu;
|
|
|
printf("请输入修改的时间:\n");
|
|
|
scanf("%ld",&h);
|
|
|
stu.a=h;
|
|
|
fp=fopen("out.dat","w");
|
|
|
for(i=0;i<k;i++)
|
|
|
fprintf(fp,"%d %s %.1f %ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
fclose(fp);
|
|
|
printf("修改成功\n");
|
|
|
return;
|
|
|
}
|
|
|
printf("没有找到该生的信息!\n");
|
|
|
return;
|
|
|
}
|
|
|
if(x==2)
|
|
|
{
|
|
|
printf("请输入修改成绩人的姓名:");
|
|
|
scanf("%s",st);
|
|
|
for(i=0;i<k;i++)
|
|
|
if(strcmp(stu.name,st)==0)
|
|
|
{
|
|
|
printf("请输入修改的成绩:\n");
|
|
|
scanf("%f",&nu);
|
|
|
stu.score=nu;
|
|
|
printf("请输入修改成绩的时间:\n");
|
|
|
scanf("%ld",&h);
|
|
|
stu.a=h;
|
|
|
fp=fopen("out.dat","w");
|
|
|
for(i=0;i<k;i++)
|
|
|
fprintf(fp,"%d %s %.1f %ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
fclose(fp);
|
|
|
printf("修改成功\n");
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
printf("没有找到该生的信息!\n");
|
|
|
}
|
|
|
|
|
|
void lookat() //(5)学生信息查询
|
|
|
{
|
|
|
char st[30];
|
|
|
int x,num;
|
|
|
k=0;
|
|
|
system("cls");
|
|
|
if((fp=fopen("out.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("Cannot open the file!\n");
|
|
|
return;
|
|
|
}
|
|
|
while(fscanf(fp,"%d%s%f%ld",stu.xh,stu.name,stu.score,stu.a)!=EOF)
|
|
|
{
|
|
|
k++;
|
|
|
}
|
|
|
printf("输入1表示用学号查询,输入2表示用姓名查询!请选择:\n");
|
|
|
scanf("%d",&x);
|
|
|
if(x==1)
|
|
|
{
|
|
|
printf("请输入查询的学号:");
|
|
|
scanf("%d",&num);
|
|
|
for(i=0;i<k;i++)
|
|
|
//if(sum[i]=stu.xh[i])
|
|
|
{
|
|
|
printf("%d%s%.1f%ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
return;
|
|
|
}
|
|
|
printf("对不起,找不到该生!\n");
|
|
|
return;
|
|
|
}
|
|
|
if(x==2)
|
|
|
{
|
|
|
printf("请输入查询的姓名:");
|
|
|
scanf("%s",st);
|
|
|
for(i=0;i<k;i++)
|
|
|
if(strcmp(stu.name,st)==0)
|
|
|
{
|
|
|
printf("%d%s%.1f%ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
return;
|
|
|
}
|
|
|
printf("对不起,找不到该生!\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void subsection() //(6)学生成绩分段
|
|
|
{
|
|
|
system("cls");
|
|
|
k=0;
|
|
|
if((fp=fopen("out.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("Cannot open the file!\n");
|
|
|
}
|
|
|
while(fscanf(fp,"%d%s%f%ld",&stu.xh,stu.name,&stu.score,&stu.a)!=EOF)
|
|
|
{
|
|
|
k++;
|
|
|
}
|
|
|
for(i=0;i<k;i++)
|
|
|
if(stu.score>=90)
|
|
|
{
|
|
|
printf("\t\t\t%d%s%.1f%ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
printf("\n\n");
|
|
|
printf("\t\t\t 90分以上学生的信息!\n");
|
|
|
}
|
|
|
for(i=0;i<k;i++)
|
|
|
if(stu.score<90&&stu.score>=80)
|
|
|
{
|
|
|
printf("\t\t\t%d%s%.1f%ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
printf("\n\n");
|
|
|
printf("\t\t\t 80到89分学生的信息!\n");
|
|
|
}
|
|
|
for(i=0;i<k;i++)
|
|
|
if(stu.score>=60&&stu.score<80)
|
|
|
{
|
|
|
printf("\t\t\t%d%s%.1f%ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
printf("\n\n");
|
|
|
printf("\t\t\t 60到79分学生的信息!\n");
|
|
|
}
|
|
|
for(i=0;i<k;i++)
|
|
|
if(stu.score<60)
|
|
|
{
|
|
|
printf("\t\t\t%d%s%.1f%ld\n",stu.xh,stu.name,stu.score,stu.a);
|
|
|
printf("\n\n");
|
|
|
printf("\t\t\t 60分以下学生的信息!\n");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|