master
m73615908 6 years ago
commit d3f6a4b61f

@ -0,0 +1,330 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student_info
{
char name[20];
char id[20];
double math;
double English;
double Chinese;
double program;
};
struct student_info s[200];
void caidan()
{
printf("********$******$***1805班******$**********$*********$*******$*****\n");
printf("** 欢迎使用学生成绩管理系统1.0 **\n");
printf("## 1.学生信息录入 ##\n");
printf("** 2.学生信息统计分析 **\n");
printf("$$ 3.学生信息显示 $$\n");
printf("** 4.学生信息排序显示 **\n");
printf("$$ 5.学生信息删除 $$\n");
printf("** 0.退出系统 **\n");
printf( "*******$***********$*******$*******$***********$******\n");
printf(" 请选择您想进行的功能:\n");
}
void xianshi(struct student_info s[], int n) //显示所有信息
{
int i;
double all=0.0;
printf("\n姓名\t\t学号\t\t数学\t英语\t语文\t程序\t总分\n");
for (i=0; i<n; i++)
{
all=s[i].math+s[i].English+s[i].Chinese+s[i].program;
printf("\n%s\t%s\t\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n", s[i].name, s[i].id, s[i].math, s[i].English, s[i].Chinese, s[i].program, all);
}
}
void baocun(struct student_info s[], int n)
{
FILE *p;
int i=0;
if((p=fopen("学生信息.txt", "w"))==NULL)
{
printf("FILE open error\n");
}
else
{
while(i<n-1)
{
fprintf(p, "%s %s %lf %lf %lf %lf\n", s[i].name, s[i].id, s[i].math, s[i].English, s[i].Chinese, s[i].program);
i++;
}
fprintf(p, "%s %s %lf %lf %lf %lf", s[i].name, s[i].id, s[i].math, s[i].English, s[i].Chinese, s[i].program);
}
fclose(p);
}
void shuru(struct student_info s[], int* n) //信息输入函数
{
int i=*n, f, h, m;
printf("请输入学生姓名:");
scanf("%s", s[i].name);
printf("请输入学生学号:");
for (f=0; ;f++)
{
m=0;
scanf("%s", s[i].id);
for (h=0; h<i;h++)
{
if (strcmp(s[i].id, s[h].id)==0)
{
m=m+1;
printf("学号重复,请重新输入学号:");
break;
}
}
if (m==0)
{
break;
}
}
printf("请输入数学成绩:");
scanf("%lf", &s[i].math);
printf("请输入英语成绩:");
scanf("%lf", &s[i].English);
printf("请输入语文成绩:");
scanf("%lf", &s[i].Chinese);
printf("请输入程序成绩:") ;
scanf("%lf", &s[i].program);
printf("添加学生信息成功!\n");
*n=*n+1;
baocun(s, *n);
}
void daochu(struct student_info s[], int* n)
{
FILE *p;
int i=*n;
if((p=fopen("学生信息.txt", "r"))==NULL)
{
n=n;
}
else
{
while(!feof(p))
{
fscanf(p, "%s%s%lf%lf%lf%lf\n", s[i].name, s[i].id, &s[i].math, &s[i].English, &s[i].Chinese, &s[i].program);
i++;
*n=*n+1;
}
}
fclose(p);
}
void paixu(struct student_info s[], int n) //排序函数
{
int i, j;
double all1, all2;
struct student_info st;
for (i=0; i<n-1; i++)
{
for (j=0; j<n-1-i; j++)
{
all1=s[j].math+s[j].English+s[j].Chinese+s[j].program;
all2=s[j+1].math+s[j+1].English+s[j+1].Chinese+s[j+1].program;
if (all1<all2)
{
st=s[j];
s[j]=s[j+1];
s[j+1]=st;
}
}
}
printf("排序后的数据:\n");
xianshi(s, n);
}
void shanchu(struct student_info s[], int* n) //删除函数
{
char num[20];
int m=0, i, j;
printf("请输入您要删除的学生学号:");
scanf("%s", num);
for (i=0; i<=*n; i++)
{
if (strcmp(s[i].id, num)==0)
{
m=m+1;
for (j=i; j<*n; j++)
{
s[j]=s[j+1];
}
*n=*n-1;
}
}
if (m==0)
{
printf("没有此学生信息!\n");
}
else
{
baocun(s, *n);
printf("已删除!\n");
}
}
void allAndAver(struct student_info s[], int n)
{
int i ;
double all=0.0, aver=0.0;
for (i=0; i<n; i++)
{
all=s[i].math+s[i].English+s[i].Chinese+s[i].program;
aver=all/4;
printf("\n%s\t%s\t\t%.1lf\t%.1lf\n", s[i].name, s[i].id, all, aver);
}
}
void bujige(struct student_info s[], int n)
{
int i, fail[4]={0,0,0,0};
for (i=0; i<n; i++)
{
if (s[i].math<60)
{
fail[0]++;
}
if (s[i].English<60)
{
fail[1]++;
}
if (s[i].Chinese<60)
{
fail[2]++;
}
if (s[i].program<60)
{
fail[3]++;
}
}
printf("\n不及格信息:\n");
printf("数学不及格的人数为:%d人\n", fail[0]);
printf("英语不及格的人数为:%d人\n", fail[1]);
printf("语文不及格的人数为:%d人\n", fail[2]);
printf("程序不及格的人数为:%d人\n", fail[3]);
}
void Max(struct student_info s[], int n) //统计单科最高分人数
{
int i, counter[4]={0,0,0,0};
double max[4]={s[0].math, s[0].English, s[0].Chinese, s[0].program};
for (i=0; i<n; i++)
{
if (s[i].math>max[0])
{
max[0]=s[i].math;
}
if (s[i].English>max[1])
{
max[1]=s[i].English;
}
if (s[i].Chinese>max[2])
{
max[2]=s[i].Chinese;
}
if (s[i].program>max[3])
{
max[3]=s[i].program;
}
}
for (i=0; i<n; i++)
{
if (s[i].math==max[0])
{
counter[0]++;
}
if (s[i].English==max[1])
{
counter[1]++;
}
if (s[i].Chinese==max[2])
{
counter[2]++;
}
if (s[i].program==max[3])
{
counter[3]++;
}
}
printf("\n最高分信息:\n");
printf("数学最高分为:%.1lf, 人数为:%d人\n", max[0], counter[0]);
printf("英语最高分为:%.1lf, 人数为:%d人\n", max[1], counter[1]);
printf("语文最高分为:%.1lf, 人数为:%d人\n", max[2], counter[2]);
printf("程序最高分为:%.1lf, 人数为:%d人\n", max[3], counter[3]);
}
void Min(struct student_info s[], int n) //统计单科最低分人数
{
int i, counter[4]={0};
double min[4]={s[0].math, s[0].English, s[0].Chinese, s[0].program};
for (i=0; i<n; i++)
{
if (s[i].math<min[0])
{
min[0]=s[i].math;
}
if (s[i].English<min[1])
{
min[1]=s[i].English;
}
if (s[i].Chinese<min[2])
{
min[2]=s[i].Chinese;
}
if (s[i].program<min[3])
{
min[3]=s[i].program;
}
}
for (i=0; i<n; i++)
{
if (s[i].math==min[0])
{
counter[0]++;
}
if (s[i].English==min[1])
{
counter[1]++;
}
if (s[i].Chinese==min[2])
{
counter[2]++;
}
if (s[i].program==min[3])
{
counter[3]++;
}
}
printf("\n各科最低分信息:\n");
printf("数学最低分为:%.1lf, 人数为:%d人\n", min[0], counter[0]);
printf("英语最低分为:%.1lf, 人数为:%d人\n", min[1], counter[1]);
printf("语文最低分为:%.1lf, 人数为:%d人\n", min[2], counter[2]);
printf("程序最低分为:%.1lf, 人数为:%d人\n", min[3], counter[3]);
}
void tongji(struct student_info s[], int n) //统计函数
{
printf("统计信息如下所示:\n");
printf("\n姓名\t\t学号\t\t总分\t平均分\n");
allAndAver(s, n);
Max(s, n);
Min(s, n) ;
bujige(s, n);
}
int main()
{
int h, n=0;
daochu(s, &n);
baocun(s, n);
while (1)
{
caidan();
scanf("%d",&h);
switch (h)
{
case 1: shuru(s, &n);break;
case 2: tongji(s, n);break;
case 3: xianshi(s, n);break;
case 4: paixu(s, n);break;
case 5: shanchu(s, &n);break;
case 0: printf("————谢谢您的使用!————\n");exit(1);break;
default: printf("请输入正确的命令!\n");
}
system("pause");
system("cls");
}
return 0;
}

Binary file not shown.
Loading…
Cancel
Save