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.

336 lines
7.2 KiB

6 years ago
#include<stdio.h>
#include<io.h>
#include <unistd.h> //int access(const char *, int); // <20><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ȩ<EFBFBD><C8A8>
#include<stdlib.h> // system()
#include<string.h>
#define MAX 200 //<2F><><EFBFBD><EFBFBD>MAX<41><58>ʾ<EFBFBD><CABE>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>
struct student //student<6E><EFBFBD><E1B9B9><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><E1B9B9><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD>Ϣ
{
char no[10]; //<2F><>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD> <20><>Ա<EFBFBD><D4B1> ѧ<><D1A7>
char name[50]; //<2F><><EFBFBD><EFBFBD>
float score; //<2F>ɼ<EFBFBD>
};
struct data //<2F><><EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>
{
int count; //ѧ<><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
struct student stu[MAX]; //<2F><EFBFBD><E1B9B9><EFBFBD>͵<EFBFBD>Ƕ<EFBFBD><C7B6>
}dd; //dd<64>ǽṹ<C7BD><E1B9B9>data<74><61><EFBFBD>͵ı<CDB5><C4B1><EFBFBD> ȫ<>ֽṹ<D6BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void menu();
void to_menu();
void add_data();
void edit_data();
void fen_shu_duan();
void query_data_name();
void query_data_no();
void sort_data_score();
void read_data();
void view_data();
void save_data();
void menu()
{
system("cls"); /*<2A><><EFBFBD><EFBFBD>*/
printf("\n\n\n\n\n");
printf("\t\t|-----------------------ѧ<><D1A7>C<EFBFBD><43><EFBFBD>Գɼ<D4B3><C9BC><EFBFBD>¼<EFBFBD><C2BC>----------------------|\n");
printf("\t\t|\t 0. <20>˳<EFBFBD> |\n");
printf("\t\t|\t 1. <20><EFBFBD><E9BFB4><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>ɼ<EFBFBD> |\n");
printf("\t\t|\t 2. <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>ɼ<EFBFBD> |\n");
printf("\t\t|\t 3. <20>޸<EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>ɼ<EFBFBD> |\n");
printf("\t\t|\t 4. <20><>ѯ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD> |\n");
printf("\t\t|\t 5. <20><>ѯ<EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |\n");
printf("\t\t|\t 6. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |\n");
printf("\t\t|\t 7. <20>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |\n");
printf("\t\t|----------------------------------------------------------------|\n");
printf("\t\t ");
}
//<2F>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>˵<EFBFBD>
void to_menu()
{
char c1,c2;
printf("\n\n<EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>");
scanf("%c%c",&c1,&c2); //<2F><>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>ϴε<CFB4>ȷ<EFBFBD>ϻس<CFBB><D8B3><EFBFBD>
menu();
}
/*
<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
0 = <EFBFBD><EFBFBD>ɫ 8 = <EFBFBD><EFBFBD>ɫ
1 = <EFBFBD><EFBFBD>ɫ 9 = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
2 = <EFBFBD><EFBFBD>ɫ A = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
3 = dz<EFBFBD><EFBFBD>ɫ B = <EFBFBD><EFBFBD>dz<EFBFBD><EFBFBD>ɫ
4 = <EFBFBD><EFBFBD>ɫ C = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
5 = <EFBFBD><EFBFBD>ɫ D = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
6 = <EFBFBD><EFBFBD>ɫ E = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
7 = <EFBFBD><EFBFBD>ɫ F = <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
*/
int main(void)
{
system("color E9");
int fun;
read_data();
menu();
while(1)
{
printf("\t\t <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܺţ<DCBA>",&fun);
scanf("%d",&fun);
switch(fun)
{
case 0:
break;
case 1:
view_data();
break;
case 2:
add_data();
break;
case 3:
edit_data();
break;
case 4:
query_data_no();
break;
case 5:
query_data_name();
break;
case 6:
sort_data_score();
break;
case 7:
fen_shu_duan();
break;
}
if(fun==0)break;
to_menu();
}
}
void view_data() // <20><>ѯ<EFBFBD>ܱ<EFBFBD>
{
int i;
printf("ѧ<EFBFBD><EFBFBD>\t <20><><EFBFBD><EFBFBD>\t C<><43><EFBFBD>Գɼ<D4B3>");
printf("\n--------------------------------------------------------------------------\n");
for(i=0;i<dd.count;i++)
printf("%s\t%s\t%.lf\n",dd.stu[i].no,dd.stu[i].name,dd.stu[i].score);
}
void save_data()
{
FILE *fp;
int i,k;
k=dd.count;
fp=fopen("d/:chen.txt","w"); //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ա<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fwrite(&k,sizeof(int),1,fp); // k<><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĵ<DDB5>ַ <20><>k<EFBFBD><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뵽fp<66>ļ<EFBFBD><C4BC>У<EFBFBD><D0A3><EFBFBD>дһ<D0B4><D2BB> ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռsizeof(int)<29><><EFBFBD>ֽ<EFBFBD>
for(i=0;i<k;i++) //׼<><D7BC>Ҫд<D2AA><D0B4><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fwrite(&dd.stu[i].no,sizeof(struct student),1,fp);
fclose(fp); //д<><D0B4><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3>ر<EFBFBD><D8B1>ļ<EFBFBD>
}
void sort_data_score() //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
int a[2]={0,0};
int i;
int j,k;
float pass;
for(i=0;i<dd.count;i++) // forѭ<72><D1AD>ÿ<EFBFBD><C3BF>ѧ<EFBFBD>ŵ<EFBFBD>ѧ<EFBFBD><D1A7>
{
if(dd.stu[i].score>=60&&dd.stu[i].score<=100)
a[0]++;
else if(dd.stu[i].score<60)
a[1]++;
}
j=a[0];
k=a[1];
pass=j/((j+k)*1.0)*100;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>%.2f%%",pass);
}
void add_data() //<2F><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>ɼ<EFBFBD>
{
struct student st; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>st
int b;
int k;
while(1)
{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>");
printf("\nѧ<EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \tC<EFBFBD><EFBFBD><EFBFBD>Գɼ<EFBFBD>");
printf("\n-------------------------------------------------------------------------------\n");
scanf("%s%s%f",st.no,st.name,&st.score);
k=dd.count;
strcpy(dd.stu[k].no,st.no);
strcpy(dd.stu[k].name,st.name);
dd.stu[k].score=st.score;
dd.count++;
printf("\n\n<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ[1-Yes 0-No]:");
scanf("%d",&b);
if(b==0)break;
}
save_data();
}
void read_data() //<2F><><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
FILE *fp;
int i,k;
struct student st;
k=0;
if((fp=fopen("d:/chen.txt","r"))==NULL) // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
dd.count=0;
}
else
{
fread(&k,sizeof(int),1,fp);
dd.count=k;
for(i=0;i<k;i++)
{
fread(&dd.stu[i],sizeof(struct student),1,fp);
}
fclose(fp);
}
}
void edit_data() //<2F>޸<EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>ɼ<EFBFBD>
{
int i,k;
char no[10],name[50];
float score;
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>޸<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD>");
scanf("%s",no);
k=-1;
for(i=0;i<dd.count;i++) //forѭ<72><D1AD>ÿ<EFBFBD><C3BF>ѧ<EFBFBD>ŵ<EFBFBD>ѧ<EFBFBD><D1A7>
{
if(strcmp(dd.stu[i].no,no)==0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ
{
k=i;
break;
}
}
if(k==-1)
{
printf("û<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ͬѧ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>-%s<><73>",no);
}
else
{
printf("\nѧ<EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \tC<EFBFBD><EFBFBD><EFBFBD>Գɼ<EFBFBD>");
printf("\n-------------------------------------------------------------------------------\n");
scanf("%s%s%f",no,name,&score);
strcpy(dd.stu[k].no,no);
strcpy(dd.stu[k].name,name);
dd.stu[k].score=score;
save_data();
printf("\n\n<EFBFBD>༭ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>-%s<><73><EFBFBD>ɹ<EFBFBD>!",no);
}
}
void query_data_no() //<2F><>ѧ<EFBFBD>Ų<EFBFBD><C5B2>ҳɼ<D2B3>
{
int i,k;
char no[10];
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD>");
scanf("%s",no);
k=-1;
for(i=0;i<dd.count;i++) //forѭ<72><D1AD>ÿ<EFBFBD><C3BF>ѧ<EFBFBD>ŵ<EFBFBD>ѧ<EFBFBD><D1A7>
{
if(strcmp(dd.stu[i].no,no)==0) //<2F><>λ<EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>ѧ<EFBFBD>ź<EFBFBD>no<6E><6F><EFBFBD><EFBFBD>֤ͬ<CDAC><D6A4><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>
{
if(k==-1)
{
printf("\n\nѧ<EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\tC<EFBFBD><EFBFBD><EFBFBD>Գɼ<EFBFBD>");
printf("\n--------------------------------------\n");
}
k=i;
printf("%s\t%s\t%.1f\n",dd.stu[i].no,dd.stu[i].name,dd.stu[i].score);
}
}
if(k==-1) //kֵû<D6B5><C3BB>
{
printf("\n\nû<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD>ѧ<EFBFBD><EFBFBD>-%s<><73><EFBFBD><EFBFBD>",no);
}
}
//<2F><>ѯѧ<D1AF><D1A7>
void query_data_name() //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳɼ<D2B3>
{
int i,k;
char name[50];
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%s",name);
k=-1;
for(i=0;i<dd.count;i++) //forѭ<72><D1AD>ÿ<EFBFBD><C3BF>ѧ<EFBFBD>ŵ<EFBFBD>ѧ<EFBFBD><D1A7>
{
if(strcmp(dd.stu[i].name,name)==0) //<2F><>λ<EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA> <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>name<6D><65><EFBFBD><EFBFBD>֤ͬ<CDAC><D6A4><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>
{
if(k==-1)
{
printf("\n\nѧ<EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\tC<EFBFBD><EFBFBD><EFBFBD>Գɼ<EFBFBD>");
printf("\n------------------------------\n");
}
k=i;
printf("%s\t%s\t%.1f\n",dd.stu[i].no,dd.stu[i].name,dd.stu[i].score);
}
}
if(k==-1)
{
printf("\n\nû<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-%s<><73><EFBFBD><EFBFBD>",name);
}
}
void fen_shu_duan() //ѧ<><D1A7><EFBFBD>ɼ<EFBFBD><C9BC>ֶ<EFBFBD>
{
int a[5]={0,0,0,0,0};
int i;
for(i=0;i<dd.count;i++) //forѭ<72><D1AD>ÿ<EFBFBD><C3BF>ѧ<EFBFBD>ŵ<EFBFBD>ѧ<EFBFBD><D1A7>
{
if(dd.stu[i].score<60)
a[0]++;
else if(dd.stu[i].score>=60&&dd.stu[i].score<=69)
a[1]++;
else if(dd.stu[i].score>=70&&dd.stu[i].score<=79)
a[2]++;
else if(dd.stu[i].score>=80&&dd.stu[i].score<=89)
a[3]++;
else
a[4]++;
}
printf("\t\t60<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>%d\n",a[0]);
printf("\t\t60~69<36>֣<EFBFBD>%d\n",a[1]);
printf("\t\t70~79<37>֣<EFBFBD>%d\n",a[2]);
printf("\t\t80~89<38>֣<EFBFBD>%d\n",a[3]);
printf("\t\t90<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>%d\n",a[4]);
}