首頁>Club>
11
回覆列表
  • 1 # 橘生淮南北島味少

    可以參考

    #include"stdio.h"/*I/O函式*/

    #include"stdlib.h"/*其它說明*/

    #include"string.h"/*字串函式*/

    #include"conio.h"/*螢幕操作函式*/

    #include"mem.h"/*記憶體操作函式*/

    #include"ctype.h"/*字元操作函式*/

    #include"alloc.h"/*動態地址分配函式*/

    structscore

    {

    intmingci;

    charxuehao[8];

    charmingzi[20];

    floatscore[6];

    }data,info[1000];

    inti,j,k=0;

    chartemp[20],ch;

    FILE*fp,*fp1;

    voidshuru()

    {

    if((fp=fopen("s_score.txt","ab+"))==NULL)

    {

    printf("cannotopenthisfile.\n");

    getch();exit(0);

    }

    for(i=0;i

    {

    printf("\nPleaseshuruxuehao:");

    gets(data.xuehao);

    printf("Pleaseshurumingzi:");

    gets(data.mingzi);

    printf("Pleaseshuruyuwenscore:");

    gets(temp);data.score[0]=atof(temp);

    printf("Pleaseshurushuxuescore:");

    gets(temp);data.score[1]=atof(temp);

    printf("Pleaseinputyingyuscore:");

    gets(temp);data.score[2]=atof(temp);

    printf("Pleaseshuruwuliscore:");

    gets(temp);data.score[3]=atof(temp);

    printf("Pleaseshurhuaxuescore:");

    gets(temp);data.score[4]=atof(temp);

    data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];

    fwrite(&data,sizeof(data),1,fp);

    printf("another?y/n");

    ch=getch();

    if(ch=="n"||ch=="N")

    break;

    }fclose(fp);

    }

    voidxianshi()

    {

    floats;intn;

    if((fp=fopen("s_score.txt","rb+"))==NULL)

    {

    printf("Cannotreadingthisfile.\n");

    exit(0);

    }

    for(i=0;i

    {

    if((fread(&info[i],sizeof(info[i]),1,fp))!=1)

    break;

    }

    printf("\nxuehaomingziyuwenshuxueyingyuwulihuauxuezhongfen\n");

    for(j=0,k=1;j

    {

    info[j].mingci=k;

    printf("%6s%8s%3.1f%3.1f%3.1f%3.1f%3.1f%3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],

    info[j].score[5]);

    }

    getch();

    fclose(fp);

    }

    voidxiugai()

    {

    if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)

    {

    printf("Cannotopenthisfile.\n");

    exit(0);

    }

    printf("\nPLeaseshuruxiugaixuehao:");

    scanf("%d",&i);getchar();

    while((fread(&data,sizeof(data),1,fp))==1)

    {

    j=atoi(data.xuehao);

    if(j==i)

    {

    printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);

    printf("Pleaseshurumingzi:");

    gets(data.mingzi);

    printf("Pleaseshuruyuwenscore:");

    gets(temp);data.score[0]=atof(temp);

    printf("Pleaseshurushuxuescore:");

    gets(temp);data.score[1]=atof(temp);

    printf("Pleaseinputyingyuscore:");

    gets(temp);data.score[2]=atof(temp);

    printf("Pleaseinputwuliscore:");

    gets(temp);data.score[3]=atof(temp);

    printf("Pleaseinputhuaxuescore:");

    gets(temp);data.score[4]=atof(temp);

    data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];

    }fwrite(&data,sizeof(data),1,fp1);

    }

    fseek(fp,0L,0);

    fseek(fp1,0L,0);

    while((fread(&data,sizeof(data),1,fp1))==1)

    {

    fwrite(&data,sizeof(data),1,fp);

    }

    fclose(fp);

    fclose(fp1);

    }

    voidchazhao()

    {

    if((fp=fopen("s_score.txt","rb"))==NULL)

    {

    printf("\nCannotopenthisfile.\n");

    exit(0);

    }

    printf("\nPLeaseshuruxuehaochakan:");

    scanf("%d",&i);

    while(fread(&data,sizeof(data),1,fp)==1)

    {

    j=atoi(data.xuehao);

    if(i==j)

    {

    printf("xuehao:%smingzi:%s\nyuwen:%f\nshuxue:%f\nyingyu:%f\nwuli:%f\nhuaxue:%f\n",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);

    }getch();

    }

    }

    voidshanchu()

    {

    if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)

    {

    printf("\nopenscore.txtwasfailed!");

    getch();

    exit(0);

    }

    printf("\nPleaseinputIDwhichyouwanttodel:");

    scanf("%d",&i);getchar();

    while((fread(&data,sizeof(data),1,fp))==1)

    {

    j=atoi(data.xuehao);

    if(j==i)

    {

    printf("Anykeywilldeletit.\n");

    getch();

    continue;

    }

    fwrite(&data,sizeof(data),1,fp1);

    }

    fclose(fp);

    fclose(fp1);

    remove("s_score.txt");

    rename("temp.txt","s_score.txt");

    printf("Datadeletwassuccesful!\n");

    printf("Anykeywillreturntomain.");

    getch();

    }

    main()

    {

    while(1)

    {

    clrscr();/*清螢幕*/

    gotoxy(1,1);/*移動游標*/

    textcolor(YELLOW);/*設定文字顯示顏色為黃色*/

    textbackground(BLUE);/*設定背景顏色為藍色*/

    window(1,1,99,99);/*製作顯示選單的視窗,大小根據選單條數設計*/

    clrscr();

    printf("*************welcometousestudentmanage******************\n");

    printf("*************************menu********************************\n");

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

    printf("*1>shuru2>xiugai*\n");

    printf("*3>shanchu4>chazhao*\n");

    printf("*5>xianshi6>exit*\n");

    printf("**\n");

    printf("*---------------------------------------------------------*\n");

    printf("Pleaseinputwhichyouwant(1-6):");

    ch=getch();

    switch(ch)

    {

    case"1":shuru();break;

    case"2":xiugai();break;

    case"3":shanchu();break;

    case"4":chazhao();break;

    case"5":xianshi();break;

    case"6":exit(0);

    default:continue;

    }

    }

    }

  • 中秋節和大豐收的關聯?
  • 我喜歡的女孩知道我喜歡她,總是躲著我?