• 大小: 20KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-22
  • 语言: C/C++
  • 标签: C语言  课程设计  

资源简介

课程设计,应付做来玩的,功能基本实现猜数字,排名,猜到第几轮结束,应付的所以做得很基础,大家需要的可以下来完善:)

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
typedef struct
{
 char name[20];
 int score;
}player;

void ResetRecord(int n)
{
    int i=0ja=0b=0c=0d=0e=0f=0g=0h=0k=0o=0;
    int recnum=0;
    int maxscore=0;
    float ABCDEFGHKO;
    player r[10];
    FILE *fp=NULL;
    player TempS;
    char DataFile[10]=“record“;
    if(n==1) a++;
    if(n==2) b++;
    if(n==3) c++;
    if(n==4) d++;
    if(n==5) e++;
    if(n==6) f++;
    if(n==7) g++;
    if(n==8) h++;
    if(n==9) k++;
    if(n==10) o++;
    fp=fopen(“DataFile.txt““r“);
    if(fp==NULL)
    {
        printf(“\nOpen file %s fail!End with any key.\n“DataFile);
        perror(“Open file fail“);
        fflush(stdin);
        getch();
        return;
    }
    while(fscanf(fp“%s%d“r[i].name&r[i].score)>0)
    {
        if(r[i].score==1)
        a++;
        if(r[i].score==2)
        b++;
        if(r[i].score==3)
        c++;
        if(r[i].score==4)
        d++;
        if(r[i].score==5)
        e++;
        if(r[i].score==6)
        f++;
        if(r[i].score==7)
        g++;
        if(r[i].score==8)
        h++;
        if(r[i].score==9)
        k++;
        if(r[i].score==10)
        o++;
        recnum++;
        i++;
    }
    if(recnum<10)
    {
        printf(“你的名字是:“);
        scanf(“%s“r[recnum].name);
        r[recnum].score=n;
        recnum++;
    }
    else
    {
      for(i=0;i<10;i++)
      {
         if(r[i].score>maxscore)
        {
            maxscore=r[i].score;
            j=i;
        }
      }
    if(n<=r[j].score)
     {
        printf(“你的名字是:\n“);
        scanf(“%s“r[j].name);
        r[j].score=n;
     }
    }

    A=a*1.0*100/recnum;
    B=b*1.0*100/recnum;
    C=c*1.0*100/recnum;
    D=d*1.0*100/recnum;
    E=e*1.0*100/recnum;
    F=f*1.0*100/recnum;
    G=g*1.0*100/recnum;
    H=h*1.0*100/recnum;
    K=k*1.0*100/recnum;
    O=o*1.0*100/recnum;
    fp=fopen(“DataFile.txt““w“);
    if(fp==NULL)
    {
        printf(“Open file fail!End with any key.\n“);
        perror(“Open file fail“);
        fflush(stdin);
        getch();
        exit(0);
    }
        for(i=0;i        {
            if(fprintf(fp“%s %d\n“r[i].namer[i].score)<=0)
            {
                printf(“\nWrite file fail!End with any key.\n“);
                perror(“Write file fail“);
                getch();
                exit(0);
            }
        }
        fclose(fp);
        fp=fopen(“DataFile.txt““r“);
        if(fp==NULL)
        {
        printf(“Open file fail!End with any key.\n“);
        perror(“Open file fail“);
        fflush(stdin);
        getch();
        exit(0);
        }
        printf(“记录是:\n“);
        printf(“\n名字\t\t分数\n“);
        while(fscanf(fp“%s%d“TempS.name&TempS.score)>0)
        {
            printf(“%s\t\t%d\n“TempS.nameTempS.score);
        }
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1075  2014-04-27 01:43  caishuzigame\caishuzigame.cbp

     文件        479  2014-04-27 15:51  caishuzigame\caishuzigame.depend

     文件        242  2014-04-27 19:56  caishuzigame\caishuzigame.layout

     文件         82  2014-04-27 19:56  caishuzigame\DataFile.txt

     文件       9836  2014-04-27 19:56  caishuzigame\main.c

     文件      38737  2014-04-27 19:53  caishuzigame\bin\Debug\caishuzigame.exe

     文件      13703  2014-04-27 19:53  caishuzigame\obj\Debug\main.o

     目录          0  2014-04-27 15:32  caishuzigame\bin\Debug

     目录          0  2014-04-27 15:32  caishuzigame\obj\Debug

     目录          0  2014-04-27 14:17  caishuzigame\bin

     目录          0  2014-04-27 14:17  caishuzigame\obj

     目录          0  2014-04-27 15:33  caishuzigame

----------- ---------  ---------- -----  ----

                64154                    12


评论

共有 条评论