You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xie_002/c 语言课程设计.c

331 lines
6.2 KiB

6 years ago
#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<30><35>******$**********$*********$*******$*****\n");
printf("** <20><>ӭʹ<D3AD><CAB9>ѧ<EFBFBD><D1A7><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ϵͳ1.0 **\n");
printf("## 1.ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ¼<CFA2><C2BC> ##\n");
printf("** 2.ѧ<><D1A7><EFBFBD><EFBFBD>Ϣͳ<CFA2>Ʒ<EFBFBD><C6B7><EFBFBD> **\n");
printf("$$ 3.ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ʾ $$\n");
printf("** 4.ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ **\n");
printf("$$ 5.ѧ<><D1A7><EFBFBD><EFBFBD>Ϣɾ<CFA2><C9BE> $$\n");
printf("** 0.<2E>˳<EFBFBD>ϵͳ **\n");
printf( "*******$***********$*******$*******$***********$******\n");
printf(" <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĹ<D0B5><C4B9>ܣ<EFBFBD>\n");
}
void xianshi(struct student_info s[], int n) //<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
{
int i;
double all=0.0;
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\tѧ<EFBFBD><EFBFBD>\t\t<EFBFBD><EFBFBD>ѧ\tӢ<EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD>ܷ<EFBFBD>\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("ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ.txt", "w"))==NULL)
{
printf("FILE open error<6F><72>\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) //<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EBBAAF>
{
int i=*n, f, h, m;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%s", s[i].name);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:");
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("ѧ<EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:");
break;
}
}
if (m==0)
{
break;
}
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ɼ<EFBFBD>:");
scanf("%lf", &s[i].math);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӣ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>:");
scanf("%lf", &s[i].English);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ijɼ<EFBFBD>:");
scanf("%lf", &s[i].Chinese);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>:") ;
scanf("%lf", &s[i].program);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
*n=*n+1;
baocun(s, *n);
}
void daochu(struct student_info s[], int* n)
{
FILE *p;
int i=*n;
if((p=fopen("ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ.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) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>\n");
xianshi(s, n);
}
void shanchu(struct student_info s[], int* n) //ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
char num[20];
int m=0, i, j;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:");
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("û<EFBFBD>д<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ!\n");
}
else
{
baocun(s, *n);
printf("<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>!\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<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n");
printf("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d<><64>\n", fail[0]);
printf("Ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d<><64>\n", fail[1]);
printf("<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d<><64>\n", fail[2]);
printf("<EFBFBD><EFBFBD><EFBFBD>򲻼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d<><64>\n", fail[3]);
}
void Max(struct student_info s[], int n) //ͳ<>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD><DFB7><EFBFBD><EFBFBD><EFBFBD>
{
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<EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n");
printf("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD>Ϊ<EFBFBD><EFBFBD>%.1lf, <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d<><64>\n", max[0], counter[0]);
printf("Ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD>Ϊ<EFBFBD><EFBFBD>%.1lf, <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d<><64>\n", max[1], counter[1]);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD>Ϊ<EFBFBD><EFBFBD>%.1lf, <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d<><64>\n", max[2], counter[2]);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD>Ϊ<EFBFBD><EFBFBD>%.1lf, <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d<><64>\n", max[3], counter[3]);
}
void Min(struct student_info s[], int n) //ͳ<>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>
{
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<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n");
printf("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>Ϊ<EFBFBD><EFBFBD>%.1lf, <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d<><64>\n", min[0], counter[0]);
printf("Ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>Ϊ<EFBFBD><EFBFBD>%.1lf, <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d<><64>\n", min[1], counter[1]);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>Ϊ<EFBFBD><EFBFBD>%.1lf, <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d<><64>\n", min[2], counter[2]);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>Ϊ<EFBFBD><EFBFBD>%.1lf, <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>%d<><64>\n", min[3], counter[3]);
}
void tongji(struct student_info s[], int n) //ͳ<>ƺ<EFBFBD><C6BA><EFBFBD>
{
printf("ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>\n");
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\tѧ<EFBFBD><EFBFBD>\t\t<EFBFBD>ܷ<EFBFBD>\tƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>лл<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>!<21><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");exit(1);break;
default: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
system("pause");
system("cls");
}
return 0;
}