commit 4140ffff4e3b2d94c9f59aa02ef2aa383c2ba5e7 Author: Your Name <18408000408@stu.hut.edu.cn> Date: Fri Jan 11 13:54:37 2019 +0800 first commit diff --git a/课设.c b/课设.c new file mode 100644 index 0000000..13eed54 --- /dev/null +++ b/课设.c @@ -0,0 +1,335 @@ +#include +#include +#include //int access(const char *, int); // »ñÈ¡ÎļþµÄȨÏÞ +#include // system() +#include +#define MAX 200 //¶¨ÒåMAX±íʾ¿É¼Èë×î´óѧÉúÊý + +struct student //student½á¹¹ÌåÃû £¨³ÉÔ±½á¹¹ÀàÐÍ£©¶¨ÒåÁËѧÉúµÄ»ù±¾ÐÅÏ¢ +{ + char no[10]; //³ÉÔ±±äÁ¿ ³ÉÔ±Ãû ѧºÅ + char name[50]; //ÐÕÃû + float score; //³É¼¨ +}; + +struct data //Ö÷½á¹¹ÀàÐÍ +{ + int count; //ѧÉú¸öÊý + struct student stu[MAX]; //½á¹¹ÀàÐ͵ÄǶÌ× +}dd; //ddÊǽṹÌådataÀàÐ͵ıäÁ¿ È«¾Ö½á¹¹Ìå±äÁ¿Ãû + + +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"); /*ÇåÆÁ*/ + printf("\n\n\n\n\n"); + printf("\t\t|-----------------------ѧÉúCÓïÑԳɼ¨¼Ç¼²¾----------------------|\n"); + printf("\t\t|\t 0. Í˳ö |\n"); + printf("\t\t|\t 1. ²é¿´ËùÓÐѧÉú³É¼¨ |\n"); + printf("\t\t|\t 2. ÊäÈëѧÉú³É¼¨ |\n"); + printf("\t\t|\t 3. ÐÞ¸ÄѧÉú³É¼¨ |\n"); + printf("\t\t|\t 4. ²éѯ³É¼¨£¨Ñ§ºÅ£© |\n"); + printf("\t\t|\t 5. ²éѯ³É¼¨£¨ÐÕÃû£© |\n"); + printf("\t\t|\t 6. ¼°¸ñÂÊ |\n"); + printf("\t\t|\t 7. ³É¼¨·ÖÊý¶Î |\n"); + printf("\t\t|----------------------------------------------------------------|\n"); + printf("\t\t "); + +} + +//»Øµ½Ö÷²Ëµ¥ + +void to_menu() +{ + char c1,c2; + printf("\n\n°´»Ø³µ·µ»ØÖ÷²Ëµ¥¡­"); + scanf("%c%c",&c1,&c2); //µÚÒ»¸ö×Ö·ûÈ·ÈÏÉϴεÄÈ·Èϻسµ¼ü + menu(); + } + + + /* +¶ÔÓ¦µÄÑÕÉ«Âë±í£º +0 = ºÚÉ« 8 = »ÒÉ« +1 = À¶É« 9 = µ­À¶É« +2 = ÂÌÉ« A = µ­ÂÌÉ« +3 = dzÂÌÉ« B = µ­Ç³ÂÌÉ« +4 = ºìÉ« C = µ­ºìÉ« +5 = ×ÏÉ« D = µ­×ÏÉ« +6 = »ÆÉ« E = µ­»ÆÉ« +7 = °×É« F = ÁÁ°×É« +*/ + + +int main(void) +{ + system("color E9"); + int fun; + read_data(); + menu(); + while(1) + { + printf("\t\t ÇëÊäÈ빦Äܺţº",&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() // ²éѯ×ܱí +{ + int i; + printf("ѧºÅ\t ÐÕÃû\t CÓïÑԳɼ¨"); + printf("\n--------------------------------------------------------------------------\n"); + for(i=0;i=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("¼°¸ñÂÊ£º%.2f%%",pass); + } + + +void add_data() //Ìí¼ÓѧÉú³É¼¨ +{ + struct student st; // ´´½¨½á¹¹Ìå±äÁ¿st + int b; + int k; + while(1) + { + printf("\nÇëÊäÈëѧÉúÐÅÏ¢£º"); + printf("\nѧºÅ \tÐÕÃû \tCÓïÑԳɼ¨"); + 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ÊÇ·ñ¼ÌÐøÌí¼ÓѧÉúÐÅÏ¢[1-Yes 0-No]:"); + scanf("%d",&b); + if(b==0)break; + } + save_data(); +} + + +void read_data() //½«Êý¾Ý´ÓÎļþ¶Áµ½½á¹¹ÌåÊý×éÖÐ + { + FILE *fp; + int i,k; + struct student st; + k=0; + if((fp=fopen("d:/chen.txt","r"))==NULL) // Èç¹ûÎļþ²»´æÔÚ + { + dd.count=0; + } + else + { + fread(&k,sizeof(int),1,fp); + dd.count=k; + for(i=0;i=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·ÖÒÔÏ£º%d\n",a[0]); + printf("\t\t60~69·Ö£º%d\n",a[1]); + printf("\t\t70~79·Ö£º%d\n",a[2]); + printf("\t\t80~89·Ö£º%d\n",a[3]); + printf("\t\t90·ÖÒÔÏ£º%d\n",a[4]); +} + + + +