TXT

my_systemc

By Luis Foster,2014-12-31 14:01
6 views 0
my_systemc

     /*

     * Ñ?ÉúÐÅÏ??ÜÀíϵÍ?.

     *

     */

    #include<stdio.h>

    #include<string.h>

    #include<stdlib.h>

    typedef struct /*Ñ?ÉúÐÅÏ?µÄ?á??Ìå*/

    {

     char num[20];

     char name[20];

     char sex[1];

     int age;

     int chinese;

     int math;

     int english;

    }ElemType;

    ElemType stu;/*È??Ö?äÁ?,ÁÙÊ??æ??Ñ?ÉúÐÅÏ?.*/

    typedef struct LNode/*Á??íÖеÄÑ?Éú?áµã.?ÉÓÃÔÚ?æ??Ñ?ÉúÐÅÏ?.*/ {

     ElemType data;

     struct LNode *next;

    }LNode,*LinkList;

/*ÕâÐ???ÊÇ???ÌÐòÓõ?µÄº?ÊýµÄº?ÊýÔ?ÐÍ.*/

    void welcome(void); /*??Ó?º?Êý.*/ char menu(void); /*

    Ö??˵?º?Êý,??ÓÃ??Ñ?Ôñ??ÄÜ.*/

    void display(char *); /*ÏÔÊ?ÎÄ?þÄÚÈÝ.*/ void insert(char *); /*?åÈëÑ?ÉúÐÅÏ?.*/ void delete_information(char *); /*É??ýÑ?ÉúÐÅÏ?.*/ void copy_information(ElemType *,ElemType *); /*Ñ?ÉúÐÅÏ?µÄ??ÖÆ.*/ void modify_information(char *); /*ÐÞ?ÄÑ?ÉúÐÅÏ?.*/ void find_information(char *); /*?éÑ?Ñ?ÉúÐÅÏ?.*/ void taxis_information(char *); /*ÅÅÐòÑ?ÉúÐÅÏ?.*/ void change_file(char *); /*?Ä?äÒª??ÀíµÄÎÄ?þ.*/ /*********************** Ö?º?Êý

    **************************************/

    main()

    {

     int recall=1,recall2,recall3;/*Ñ???µÄ?ØÖÆ?äÁ?.*/

     char ch;/*×Ö?û?äÁ?,?ÓÊÜ'y'?ò'n'.*/

     char filename[10];/*×Ö?ûÊý×é,?æ??Òª??ÀíµÄÎÄ?þÃû.*/

     welcome();/*µ?ÓÃ??Ó?º?Êý*/

     printf("input the name of the file which to be dealed with:");

     scanf("%s",filename);

     while(recall)/*Ñ????ØÖÆ,ÓÃÀ??ØÖÆÓÃ??ÊÇ?ñÕæµÄÍË?ö.*/

     { recall2=1;

     recall3=1;

    while(recall2)/*Ñ????ØÖÆ,ʵÏÖÍê?ÉÃ??ö??ÄܺóÔÙ?ص?Ö??˵?.*/

     {

     printf("\t\t############ file:%s ################\n" ,filename);/*?òÓ??ö??ÀíµÄÎÄ?þÃû.*/

     switch (menu())/*?ÔÓÃ???øÐеÄ??ÄÜÑ?Ôñ×??öÅÐ?Ï.*/

     {

     case '1':

     display(filename);break;

     case '2':

     insert(filename);break;

     case '3':

     delete_information(filename);break;

     case '4':

     modify_information(filename);break;

     case '5':

     find_information(filename);break;

     case '6':

     taxis_information(filename);break;

     case '7':

     change_file(filename);break;

     case 27:

     recall2=0;break;

     default :

     printf("please chose between 1 to 7\n");

     }

     printf("\n\t\t#######___Are you sure(y or n)??___#######\n");/*ÌáÊ?ÓÃ??ÊÇ?ñÕæµÄÍË?ö*/

    while(recall3)/*Ñ????ØÖÆ,Ö?µ?ÊäÈëÕýÈ?×Ö?û?ÅÄÜÍË?öÑ???.ºóÃæºÜ?à??ÊÇÓõ?ÕâÑùµÄÑ???.*/

     {

     ch=getch();

     switch(ch)

     {

     case 'y':case 'Y':

     recall=0;recall3=0;break;

     case 'n':case 'N':

     recall3=0;break;

     default:

     printf("\nyour input is wrong!!please input'y'or'n'\n");

     }

     }

     }

     printf("\n\n\t\t\tthank you for your using\n");

     printf("\t\t\t press any key to quit.");

     getch();

    }

/**************************** ??Ó?º?Êý

    *********************************/

    void welcome(void)

    {

     printf("\t\t\twelcome to the system!\n");

     printf("\t\t\t made by liuqing.\n");

     printf("\t\t\t\t\t\tcopyright@2007 by myself.\n\n\n");

     printf("press any key to continue........\n");

     getch();

    }

    /*****************************

    Ö??˵?º?Êý*********************************/

    char menu(void)

    {

     char chose;

     printf("=============================main

    menu================================\n");

     printf("================= 1: display the file. ==================\n");

     printf("================= 2: insert informations. ==================\n");

     printf("================= 3: delete informations. ==================\n");

     printf("================= 4: modify informations. ==================\n");

     printf("================= 5: find informations. ==================\n");

     printf("================= 6: taxis informations.

==================\n");

     printf("================= 7: change file to be dealed with ==================\n");

     printf("================= esc: quit the system. ==================\n");

    printf("========================================================================\n");

     printf("please chose one:");

     printf("%c",chose=getch());

     printf("\n");

     return chose;

}

/********************************

    ÏÔÊ?Ñ?ÉúÐÅÏ?µÄº?Êý************************/

    void display(char *filename)

    {

     int count=0;/*?ÇÂ?Ñ?ÉúµÄ?öÊý*/

     FILE *fp;

     if((fp=fopen(filename,"rb"))==NULL)/*?ò?ªÎÄ?þ*/

     {

     printf("this file is not exist!!\n");

     getch();

     return;

     }

     printf("**

    ============================================================== **\n");

     printf("** %-15s%-15s%-5sage chinese math english **\n","num","name","sex");

     while(!feof(fp))/*ÅÐ?ÏÎÄ?þÊÇ?ñ?áÊø.Ö?ÖÁ?áÊø?ÅÍË?öÑ???*/

     {

     count++;

     fread(&stu,sizeof(ElemType),1,fp);/*?ÁÈ?ÎÄ?þÒ?ÌõÐÅÏ?*/

     if(count {

     printf("press any key to continue show!!\n");

     printf("** %-15s%-15s%-5sage chinese math english **\n","num","name","sex");/*?òÓ?ÐÅÏ?*/

     getch();

     }

     printf("** %-15s%-15s%-5s%-5d%-9d%-6d%-5d **\n",stu.num,stu.name,stu.sex,stu.age,stu.chinese,stu.math,stu.en

    glish);

     }

     fclose(fp);

     printf("** ====================here are %d records.======================= **",count);

     printf("\n\t\t\tsuccessful\n\t press any key to return the main

    menu......\n");

     getch();/*??ÈÎÒâ?ü?ص?Ö??˵?*/

    }

    /***************************

    ?åÈëÑ?ÉúÐÅÏ?º?Êý**************************************/ void insert(char *filename)

    {

     FILE *fp;

     char ch;

     int recall=1,recall2;

     if((fp=fopen(filename,"ab+"))==NULL)

     {

     printf("file can not open!!\n");

     getch();

     return;

     }

     while(recall)/*Ñ????ØÖÆ.ʵÏÖ?à?Î?åÈëÐÅÏ?,*/

     {

     recall2=1;

     printf("\nplease input:\nnum,name,sex(m or f),age(int),chinese(int),math(int),english(int)\n");

scanf("%s%s%s%d%d%d%d",stu.num,stu.name,stu.sex,&stu.age,&stu.chin

    ese,&stu.math,&stu.english);/*ÊäÈëÐÅÏ?*/

     fwrite(&stu,sizeof(ElemType),1,fp);/*Ð?ÈëÎÄ?þÐÅÏ?*/

     printf("do you want to insert again?(y or n)");

     while(recall2)/*Ñ???,Ö?ÖÁÊäÈëÕýÈ?×Ö?û*/

     {

     ch=getch();

     switch(ch)

     {

     case 'n':case 'N':

     recall=0;recall2=0;break;

     case 'Y':case 'y':

     recall2=0;break;

     default:

     printf("\nyour input is wrong!!please input'y'or'n'\n");

     }

     }

     }

     fclose(fp);

     printf("\n\t\t\tsuccessful\n\t press any key to return the main

    menu......\n");

     getch();getchar();

}

    /************************É??ýÑ?ÉúÐÅÏ?****************************/ void delete_information(char *filename)

    {

     char chose;/*?ÓÊÜÒªÉ??ýÎÄ?þµÄÑ?Ôñ×Ö?û */

     int recall=1,recall2,recall3;/*Ñ????ØÖÆ?äÁ?*/

     char ch;

     char delete_information[20];/*?æ??ÒªÉ??ýµÄÑ?ÉúÐÅÏ?µÄÑ?ºÅ?òÃû×Ö */

     LinkList L,q,s,p;/*Ñ?ÉúÐÅÏ?µÄ?áµãÖ?Õë */

     FILE *fp;

     if((fp=fopen(filename,"rb"))==NULL)/*?ò?ªÎÄ?þ*/

     {

     printf("file can not open!!\n");

     getch();

     return;

     }

     L=(LinkList)malloc(sizeof(LNode));/*??Á??øÍ??áµãµÄÁ??í */

     L->next=NULL;

     q=L;

     while(!feof(fp))/*?ÑÑ?ÉúÐÅÏ???ÖƵ?Á??íÖÐ */

     {

     s=(LinkList)malloc(sizeof(LNode));/*ÉêÇëÒ??ö?áµã*/

     fread(&stu,sizeof(ElemType),1,fp);/*?ÁÈ?ÎÄ?þµÄÒ?ÌõÐÅÏ?*/

    copy_information(&(s->data),&stu);/*??ÖÆÒ?ÌõÐÅÏ?.*/

     s->next=NULL;

     q->next=s;

     q=q->next;

     }

     fclose(fp);

     while(recall)/*Ñ????ØÖÆ.Ö?ÖÁÊäÈë'n'Ìø?öÑ???*/

     {

     recall2=1;

     recall3=1;

     printf("by what?\n");/*ÌáÊ?Í??ýÊ?Ã???Ê?É??ýÐÅÏ? */

     while(recall2)/*Ñ????ØÖÆ.ÊäÈëÕýÈ?×Ö?û'1'?ò'2'?ÅÌø?öÑ???*/

     {

     printf("1: num\n");

     printf("2: name\nplease chose one:");

    printf("%c",chose=getch());/*?òÓ?Ñ?ÔñµÄ×Ö?û.ÀûÓÃÁËgetch()º?Êý.*/

     switch(chose)/*ÅÐ?ÏÑ?ÔñµÄ×Ö?û.*/

     {

     case '1':

     recall2=0;/*ÊäÈë×Ö?ûÕýÈ?,Ö?ÐÐÍê?ÉÌø?öÑ??? */

     printf("\nplease input the num:");

     scanf("%s",delete_information);

     q=L->next;

     p=L;

     while( q &&

    strcmp((q->data).num,delete_information) )/*?È?ÏÊÇ?ñÏàµÈ.*/

     {

     p=q;

     q=q->next;

     }

     if(q)/*Èç?ûÕÒµ?É??ýÐÅÏ? */

     {

     p->next=q->next;/*ÔÚÁ??íÖÐÉ??ý*/

     free(q);/*ÊÍ?Å?áµã?Õ?ä */

    if((fp=fopen(filename,"wb"))==NULL)/*?ò?ªÎÄ?þ*/

     {

     printf("file can not open!!\n");

     getch();

     return;

     }

     q=L->next;

     while(q)/*?ÑÁ??íÖÐÐÅÏ?Ð?ÈëÎÄ?þ*/

     {

     copy_information(&stu,&(q->data));

     fwrite(&stu,sizeof(ElemType),1,fp);

     q=q->next;

     }

     fclose(fp);/*?Ø?ÕÎÄ?þ*/

     }

     else

     printf("\nsorry!! does not have this num.\n");

     break;

     case '2':/*?ù??ºÍÉÏÃæµÄÒ?Ñù.ËùÒÔ??×ö×?ÊÍÁË */

     recall2=0;

     printf("\nplease input the name:");

     scanf("%s",delete_information);

     q=L->next;

     p=L;

     while(q &&

    strcmp((q->data).name,delete_information))

     {

     p=q;

     q }

     if(q)

     {

     p->next=q->next;

     free(q);

     if((fp=fopen(filename,"wb"))==NULL)

     {

     printf("file can not open!!\n");

     getch();

     return;

     }

     q=L->next;

     while(q)

     {

     copy_information(&stu,&(q->data));

     fwrite(&stu,sizeof(ElemType),1,fp);

     q=q->next;

     }

     fclose(fp);

     }

     else

     printf("\nsorry!! does not have this name.\n");

     break;

     default:

     printf("\nyour input is wrong!!please input '1'

    or '2'.\n");

     }

     }

     printf("\ndo you want to delete again?(y or n)");

     while(recall3)/*Ñ???Ö?ÖÁÊäÈëÕýÈ?×Ö?û */

     {

     ch=getch();

     switch(ch)

     {

     case 'n':case 'N':

     recall=0;recall3=0;break;

     case 'Y':case 'y':

     recall3=0;break;

     default:

     printf("\nyour input is wrong!!please input'y'or'n'\n");

     }

     }

     }

     printf("\n\t\t\tsuccessful\n\t press any key to return the main

    menu......\n");

     getch();getchar();

    }

/**********************

    Ò?ÌõÐÅÏ?µÄ??ÖÆ********************************/

    void copy_information(ElemType *copy1,ElemType *copy2) {

     strcpy((*copy1).num,(*copy2).num);

     strcpy((*copy1).name,(*copy2).name);

     strcpy((*copy1).sex,(*copy2).sex);

     (*copy1).age=(*copy2).age;

     (*copy1).chinese=(*copy2).chinese;

     (*copy1).math=(*copy2).math;

     (*copy1).english=(*copy2).english;

    }

/**************************ÐÞ?ÄÑ?ÉúÐÅÏ?***************************

    ****/

    void modify_information(char *filename)

    {

     char modify[20];/*?æ??ÒªÐÞ?ÄÑ?ÉúÐÅÏ?µÄÐÕÃû?òÑ?ºÅ */

     char ch;

     int count;/*?ÇÂ?Ñ?ÉúÐÅÏ?ÔÚÎÄ?þÖеÄÎ?Öà */

     char chose;/*?ÓÊÜÑ?ÔñµÄ×Ö?û */

     int unfind;/*ÅÐ?ÏÐÅÏ?ÊÇ?ñÕÒµ? */

     int recall,recall2,recall3;/*Ñ????äÁ?*/

     FILE *fp;

     if((fp=fopen(filename,"rb+"))==NULL)/*?ò?ªÎÄ?þ*/

     {

     printf("file can not open!!\n");

     getch();

     return;

     }

     recall=1;

     while(recall)/*?ù??ºÍÇ????ö??ÄܵÄÑ???Ò?Ñù,?Í??×ö?âÊÍÁË*/

     {

     count=0;

     unfind=1;

     recall2=1;

     printf("by what?\n");

     while(recall2)

     {

     printf("1: num\n");

     printf("2: name\nplease chose one:");

     printf("%c",chose=getch());

     switch(chose)

     {

     case '1':

     recall2=0;

     rewind(fp);

     printf("input the num:\n");

     scanf("%s",modify);

     while(!feof(fp))

     {

     fread(&stu,sizeof(ElemType),1,fp);/*?ÁÈ?ÐÅÏ?*/

     count++;/*Î?ÖõÝÔö*/

     if(!strcmp(stu.num,modify))/*Èç?ûÕÒµ?*/

     {

Report this document

For any questions or suggestions please email
cust-service@docsford.com