| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2608 人关注过本帖
标题:求助 如何输出个学院的总分
只看楼主 加入收藏
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>


struct table_game//定义一个全局的结构体
{
    char xmmc[11];//项目名称
    char xymc[13];//所属学院名称
    int mc;   //名次
};
struct table_zf
{
    char xymc[13];
    int fs;
};
//定义结构体数组(全局)
struct table_game GAME[1000];
struct table_zf   ZF[100];
int x = 0;//定义项目数


          //定义一个全局变量存放实际的人数
int sjs = 0;
//输入比赛成绩
void input()
{
    int n, i, j, index = 0;
    char temp[11];
    char wrong[100];//用来存放输入选择时候手误输入可能的字符
    system("cls");
    printf("***************************************************************************\n");
    printf("***             亲,欢迎来到运动员成绩录入功能!                         ***\n");
    printf("***************************************************************************\n");

    //sjs = 0;

    for (i = sjs; i <= 999; i++)
    {
        printf("\n********************************************************************\n");
        printf("*****                      亲,是否要录入比赛成绩!               *****\n");
        printf("---                             1、是哒!                           ---\n");
        printf("---                             2、不是哒!                         ---\n");
        printf("\n********************************************************************\n");

        printf("亲,请输入你的选择(1 or 2):");
        scanf("%d", &n);
        gets(wrong);

        while (n != 1 && n != 2)
        {
            printf("亲,你输得不是(1 or 2),请重新输入(1 or 2):");
            scanf("%d", &n);
            gets(wrong);
        }
        if (n == 2)
        {
            printf("over\n");
            break;
        }
        else
        {

            //正常情况下一个运动员的所有信息录入

            printf("输入项目名称:");
            gets(GAME[i].xmmc);

            //for (j = 0; j<7; j++)
            {
                //GAME[index].xmmc[j] = temp[j];
                   int temp = 0;
                printf("输入运动员所属学院名称:");
                gets(GAME[i].xymc);

                printf("输入名次:");
                scanf("%d", &temp);
                GAME[i].mc = temp;
                gets(wrong);
                sjs++;
            }
        }
    }
    system("pause");
}


void output()
{
    int i, j;
    system("cls");
    printf("%-11s", "项目名称");
    printf("%-13s", "所属学院名称");
    printf("%-7s", "名次");
    printf("\n");

    for (i = 0; i <= sjs; i++)
    {
       printf("%-11s", GAME[i].xmmc);
       printf("%-13s", GAME[i].xymc);
       printf("%-7d", GAME[i].mc);
       printf("\n");
    }
    system("pause");
}
//保存数据
void save()
{
    FILE *p;
    int n,i;
    char wrong[100];
    system("cls");

    printf("************************************************************************\n");
    printf("***                    亲,欢迎来到数据保存功能                      ***\n");
    printf("***                    1、确定保存   2、放弃保存                     ***\n");
    printf("************************************************************************\n");

    printf("亲,请输入你的选择(1 or 2):");
    scanf("%d", &n);
    gets(wrong);
    while (n != 1 && n != 2)
    {
        printf("亲,你输入的不是(1 or 2),请重新输入(1 or 2)");
        scanf("%d", &n);
        gets(wrong);
    }
    if (n == 1)
    {
        p = fopen("d:\\保存数据.txt", "w+");
        if (p == NULL)
        {
            printf("数据保存失败!\n");
            exit(0);
        }
        else
        {
            for (i = 0; i < sjs; i++)
            {
                fprintf(p,"%s  %s  %d\n",GAME[i].xmmc,GAME[i].xymc,GAME[i].mc);
            }
            printf("亲,数据保存成功了哟!\n");
            fclose(p);
        }
    }
    else
    {
        printf("放弃数据保存,返回主菜单!\n");
    }
    system("pause");
}
//读取函数
void load()
{
    FILE*p;
    int n,m=1;
    char wrong[100];
    system("cls");
    printf("************************************************************************\n");
    printf("***                    亲,欢迎进入信息读取功能                      ***\n");
    printf("***                    1、确定读取      2、放弃读取                  ***\n");
    printf("************************************************************************\n");
    printf("亲,请输入你的选择(1 or 2):");
    scanf("%d", &n);
    gets(wrong);
    while (n != 1 && n != 2)
    {
        printf("亲,你输入的不是(1 or 2),请重新输入(1 or 2):");
        scanf("%d", &n);
        gets(wrong);
    }
    if (n == 1)
    {
          p = fopen("d:\\保存数据.txt", "r+");
        if (p == NULL)
        {
            printf("文件打开失败!\n");
            exit(0);
        }
        else
        {
            char str[3][20];
            int k=0;
            while (m==1)
            {
                fscanf(p,"%s%s%s",str[0],str[1],str[2]);
                if(feof(fp))  break;
                k=atoi(str[2]);
                GAME[sjs].mc=k;
                strcpy(GAME[sjs].xmmc,str[0]);
                strcpy(GAME[sjs].xymc,str[1]);
                sjs++;
            }
            int i;
            for(i=0;i<sjs;i++)
            printf("%s  %s   %d\n",GAME[i].xmmc,GAME[i].xymc,GAME[i].mc);
            printf("亲,数据读取成功了哟!\n");
            fclose(p);
        }
    }
    else
    {
        printf("确定放弃数据读取,即将返回主菜单\n");
    }
    system("pause");
}

//查询比赛成绩
void search()
{
    int n, i, j, flag;
    char search_xmmc[11];
    int  search_mc;
    char search_xymc[13];
    char wrong[100];

    system("cls");

    printf("***********************************************************************\n");
    printf("***                 亲,欢迎来到查询比赛成绩功能                    ***\n");
    printf("***                     1、按照项目名称查询                         ***\n");
    printf("***                     2、按照名次查询                             ***\n");
    printf("***                     3、查询参赛院信息                           ***\n");
    printf("***                     4、退出查询 返回菜单                        ***\n");
    printf("***********************************************************************\n");
    printf("亲,请输入你的选择(1 or 2 or 3 or 4):");
    scanf("%d", &n);
    gets(wrong);
    while (n != 1 && n != 2 && n != 3 && n != 4)
    {
        printf("亲,你输入的不是(1 or 2 or 3 or 4),请重新输入(1 or 2 or 3 or 4)");
        scanf("%d", &n);
        gets(wrong);
    }

    switch (n)
    {
    case 1:
        printf("请输入要查询的项目名称:");
        gets(search_xmmc);


        for (j = 0; j<sjs; j++)

        {
            flag = 0;
            //puts(GAME[i].xmmc == 0);
            if (strcmp(search_xmmc, GAME[j].xmmc) == 0)
            {
                flag = 1;
                printf("******                 按项目名称查询有以下结果         ******\n");
                printf("***                      名次       学院                 ***\n ");
                printf("*************************************************************\n");
                printf("%7d%7s\n", GAME[j].mc, GAME[j].xymc);
                break;
            }
        }


        if (flag == 0)
        {
            printf("查无此项目!\n");
        }
        break;
    case 2:
        printf("请输入名次:");
        scanf("%d", &search_mc);

        for (j = 0; j<sjs; j++)
        {
            flag = 0;
            //puts(GAME[i].mc == 0);
            if (search_mc == GAME[j].mc)
            {
                flag = 1;
                printf("******                 按名次查询有以下结果           ******\n");
                printf("***                  项目名称       学院                 ***\n ");
                printf("*************************************************************\n");
                printf("%11s%7s\n", GAME[j].xmmc, GAME[j].xymc);
                break;
            }
        }

        if (flag == 0)
        {
            printf("该名次不存在!\n");
        }
        break;
    case 3:
        printf("请输入学院名称:");
        gets(search_xymc);

        for (j = 0; j<sjs; j++)
        {
            flag = 0;
            //puts(GAME[i].xymc == 0);
            if (strcmp(search_xymc, GAME[j].xymc) == 0)
            {
                flag = 1;
                printf("******                 按学院名称查询有以下结果        ******\n");
                printf("***                  项目名称       名次                 ***\n ");
                printf("*************************************************************\n");

                printf("%11s%7d\n", GAME[j].xmmc, GAME[j].mc);
                break;
            }
        }

        if (flag == 0)
        {
            printf("该学院不存在!\n");
        }
        break;
    case 4: break;
    }
    system("pause");
}

//显示团体总分排序
void sort()
{
    int i, j;
    struct table_game t;
    system("cls");
    printf("******                   团体总分显示如下              *****\n");
    printf("******                  学院    总成绩     名次        *****\n");
    printf("************************************************************\n");
    for (i = 0; i < sjs; i++);
    {
        for (j = 0; j< sjs; j++)
        {
            if (GAME[j].mc<GAME[j + 1].mc)
            {
                t = GAME[j];
                GAME[j] = GAME[j + 1];
                GAME[j + 1] = t;
            }

        }

    }
    output();
}
//统计总分
char* get_name(int i)
{
    switch (i)
    {
        case 1:
            return "建管学院:";
        case 2:
            return "土木学院:";
        case 3:
            return "经管学院:";
        case 4:
            return "人文学院:";
        case 5:
            return "艺术学院:";
        case 6:
            return "电气学院:";
        case 7:
            return "建筑学院:";
        default:
            return "其他:";
    }
}

void tongji()
{
    int i;
    char wrong[100];
    system("cls");
    printf("***         亲,欢迎来到总分统计栏目      ***\n");
    for(i=1;i<8;i++)
    ZF[i].fs=0;
    for (i = 0; i < sjs; i++)
    {
        if (GAME[i].mc == 1)
        {
            if (strcmp(GAME[i].xymc, "建管学院") == 0)
                ZF[1].fs += 10;
            if (strcmp(GAME[i].xymc, "土木学院") == 0)
                ZF[2].fs += 10;
            if (strcmp(GAME[i].xymc, "经管学院") == 0)
                ZF[3].fs += 10;
            if (strcmp(GAME[i].xymc, "人文学院") == 0)
                ZF[4].fs += 10;
            if (strcmp(GAME[i].xymc, "艺术学院") == 0)
                ZF[5].fs += 10;
            if (strcmp(GAME[i].xymc, "电气学院") == 0)
                ZF[6].fs += 10;
            if (strcmp(GAME[i].xymc, "建筑学院") == 0)
                ZF[7].fs += 10;
        }
        if (GAME[i].mc == 2)
        {
            if (strcmp(GAME[i].xymc, "建管学院") == 0)
                ZF[1].fs += 8;
            if (strcmp(GAME[i].xymc, "土木学院") == 0)
                ZF[2].fs += 8;
            if (strcmp(GAME[i].xymc, "经管学院") == 0)
                ZF[3].fs += 8;
            if (strcmp(GAME[i].xymc, "人文学院") == 0)
                ZF[4].fs += 8;
            if (strcmp(GAME[i].xymc, "艺术学院") == 0)
                ZF[5].fs += 8;
            if (strcmp(GAME[i].xymc, "电气学院") == 0)
                ZF[6].fs += 8;
            if (strcmp(GAME[i].xymc, "建筑学院") == 0)
                ZF[7].fs += 8;
        }
        if (GAME[i].mc == 3)
        {
            if (strcmp(GAME[i].xymc, "建管学院") == 0)
                ZF[1].fs += 6;
            if (strcmp(GAME[i].xymc, "土木学院") == 0)
                ZF[2].fs += 6;
            if (strcmp(GAME[i].xymc, "经管学院") == 0)
                ZF[3].fs += 6;
            if (strcmp(GAME[i].xymc, "人文学院") == 0)
                ZF[4].fs += 6;
            if (strcmp(GAME[i].xymc, "艺术学院") == 0)
                ZF[5].fs += 6;
            if (strcmp(GAME[i].xymc, "电气学院") == 0)
                ZF[6].fs += 6;
            if (strcmp(GAME[i].xymc, "建筑学院") == 0)
                ZF[7].fs += 6;
        }
        if (GAME[i].mc == 4)
        {
            if (strcmp(GAME[i].xymc, "建管学院") == 0)
                ZF[1].fs += 5;
            if (strcmp(GAME[i].xymc, "土木学院") == 0)
                ZF[2].fs += 5;
            if (strcmp(GAME[i].xymc, "经管学院") == 0)
                ZF[3].fs += 5;
            if (strcmp(GAME[i].xymc, "人文学院") == 0)
                ZF[4].fs += 5;
            if (strcmp(GAME[i].xymc, "艺术学院") == 0)
                ZF[5].fs += 5;
            if (strcmp(GAME[i].xymc, "电气学院") == 0)
                ZF[6].fs += 5;
            if (strcmp(GAME[i].xymc, "建筑学院") == 0)
                ZF[7].fs += 5;
        }
        if (GAME[i].mc == 5)
        {
            if (strcmp(GAME[i].xymc, "建管学院") == 0)
                ZF[1].fs += 4;
            if (strcmp(GAME[i].xymc, "土木学院") == 0)
                ZF[2].fs += 4;
            if (strcmp(GAME[i].xymc, "经管学院") == 0)
                ZF[3].fs += 4;
            if (strcmp(GAME[i].xymc, "人文学院") == 0)
                ZF[4].fs += 4;
            if (strcmp(GAME[i].xymc, "艺术学院") == 0)
                ZF[5].fs += 4;
            if (strcmp(GAME[i].xymc, "电气学院") == 0)
                ZF[6].fs += 4;
            if (strcmp(GAME[i].xymc, "建筑学院") == 0)
                ZF[7].fs += 4;
        }
        if (GAME[i].mc == 6)
        {
            if (strcmp(GAME[i].xymc, "建管学院") == 0)
                ZF[1].fs += 3;
            if (strcmp(GAME[i].xymc, "土木学院") == 0)
                ZF[2].fs += 3;
            if (strcmp(GAME[i].xymc, "经管学院") == 0)
                ZF[3].fs += 3;
            if (strcmp(GAME[i].xymc, "人文学院") == 0)
                ZF[4].fs += 3;
            if (strcmp(GAME[i].xymc, "艺术学院") == 0)
                ZF[5].fs += 3;
            if (strcmp(GAME[i].xymc, "电气学院") == 0)
                ZF[6].fs += 3;
            if (strcmp(GAME[i].xymc, "建筑学院") == 0)
                ZF[7].fs += 3;
        }
        if (GAME[i].mc == 7)
        {
            if (strcmp(GAME[i].xymc, "建管学院") == 0)
                ZF[1].fs += 1;
            if (strcmp(GAME[i].xymc, "土木学院") == 0)
                ZF[2].fs += 1;
            if (strcmp(GAME[i].xymc, "经管学院") == 0)
                ZF[3].fs += 1;
            if (strcmp(GAME[i].xymc, "人文学院") == 0)
                ZF[4].fs += 1;
            if (strcmp(GAME[i].xymc, "艺术学院") == 0)
                ZF[5].fs += 1;
            if (strcmp(GAME[i].xymc, "电气学院") == 0)
                ZF[6].fs += 1;
            if (strcmp(GAME[i].xymc, "建筑学院") == 0)
                ZF[7].fs += 1;
        }


    }

    for (i = 1; i < 8; i++)
    {
        printf("%s%d\n", get_name(i),ZF[i].fs);
    }

    system("pause");

}

//菜单函数
void menu()
{
    time_t t;
    struct tm *p;
    int n;

    t = time(NULL);
    p = (struct tm *)localtime(&t);

    system("cls");

    printf("                             运动会管理系统                \n");
    printf("          %d-%d-%d  %d:%d:%d\n", p->tm_year + 1990, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
    printf("***********************************************************\n");
    printf("---               1、录入比赛成绩功能                  ----\n");
    printf("---               2、查询各个比赛项目的成绩            ----\n");
    printf("---               3、显示团体总分报表                  ----\n");
    printf("---               4、统计总分                          ----\n");
    printf("---               5、保存数据                          ----\n");
    printf("---               6、读取数据                          ----\n");
    printf("---               7、退出系统                          ----\n");
    printf("***********************************************************\n");

    printf("请输入你的选择(1-7):");
    scanf("%d", &n);

    while (n<0 || n>7)
    {
        printf("亲,输错了,请重新输入(1-7)");
        scanf("%d", &n);
    }
    switch (n)
    {
    case 1: input(); menu(); break;
    case 2: search(); menu(); break;
    case 3: sort();  menu(); break;
    case 4: tongji(); menu(); break;
    case 5: save();  menu(); break;
    case 6: load();  menu(); break;
    case 7: exit(0); menu(); break;
    }
}
//主函数
int main()
{
    menu();//直接调用
    system("pause");
    return 0;
}

[此贴子已经被作者于2016-6-30 12:40编辑过]

2016-06-25 17:36
SR忘
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-6-22
收藏
得分:0 
回复 21楼 linlulu001
谢大神,辛苦帮我改,但是显示的还是零分。大神能把你那边关于统计分数的截图调成白底黑字发一份给我吗?我需要粘贴到报告里去
2016-06-25 17:48
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:0 
我图片发给你吧,你自己PS下。
图片附件: 游客没有浏览图片的权限,请 登录注册
2016-06-25 17:50
SR忘
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-6-22
收藏
得分:0 
回复 23楼 linlulu001
好的
2016-06-25 17:51
SR忘
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-6-22
收藏
得分:0 
回复 23楼 linlulu001
大神这个我怎么p呀,老师要求白底黑字,打印出来才方便看
2016-06-25 17:52
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:0 
你P吧,如果时间够的话
图片附件: 游客没有浏览图片的权限,请 登录注册
2016-06-25 18:06
SR忘
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-6-22
收藏
得分:0 
回复 26楼 linlulu001
好艰巨的任务!拖着成为全班最后交作业的先
2016-06-25 18:07
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:0 
能交差就行了。
2016-06-25 18:15
SR忘
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-6-22
收藏
得分:0 
回复 26楼 linlulu001
p不出来我放弃了
2016-06-25 18:16
SR忘
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-6-22
收藏
得分:0 
回复 28楼 linlulu001
这个图太明显没按他的要求来,作业不过关,就会被刷下来,一直修改到让他满意才可以离校。
2016-06-25 18:18
快速回复:求助 如何输出个学院的总分
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024504 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved