为了账号安全,请及时绑定邮箱和手机立即绑定

数据结构课程设计——运动会分数统计

2019.12.20 08:56 1248浏览

#include
#include <stdio.h>
#include <stdlib.h>
#include<Windows.h>
#include <string.h>

#define Schnum 6 // school 个数
#define Pronum 6// project 个数
#define N 3 //前n名
#define M 5 //前m名

void intzoom(int a, int b);
void screen();
void schoolman();
void schoolwomen();
void backup();
void Integral(int intergalgrade[][Pronum]);
void bubble_sort();
void mao(int n);
void transition(int intergalgrade[][Pronum]);
void PRINTF(int bb);
void First_Rank();
void calibrate();
void ask_for(int k, int intergalgrade[][Pronum]);
void allgrade(int intergalgrade[][Pronum]);

typedef struct//每个学校派一名参加比赛
{
int Allgrade; //总分
int callgrade;
int rankall;

int Boygrade;//男生分数 
int cboygrade;
int rankboy;

int Girlgrade; //女生分数 
int rankgirl;
int cgirlgrade;

int prograde[Pronum];  //每个学校项目成绩
int cprograde[Pronum];  //copy
int rank[Pronum];  //学校比赛成绩等级schoolrank
char schname[20]; //学校的名字 

}SCH;//学校结构体 项目school

typedef struct
{
char proname[20]; //项目的名字
}PRO;//学校结构体 项目

SCH school[Schnum];

PRO project[Pronum];

void intzoom(int a,int b) //初始化结构体中的结构数据
{
int i, j;
for (i = 0; i < a; i++)
{
school[i].Allgrade = 0;
school[i].Boygrade = 0;
school[i].Girlgrade = 0;
school[i].rankall = i;
school[i].rankboy = i;
school[i].rankgirl = i;
for (j = 0; j < b; j++)
{
school[i].prograde[j] = 0;
school[i].cprograde[j] = 0;
school[i].rank[j] = i;
}
}
}

//显示屏项目
void screen()
{
printf("\t\t\t……………………………………………………………………………………………………\n");
printf("\t\t\t……………………………………【运动会分数统计】………………………………………\n");
printf("\t\t\t- ※首先请输入你想比较:学校名称和项目名称 -\n");
printf("\t\t\t- First. 学校各个运动项目成绩录入 -\n");
printf("\t\t\t- 1.输出各个项目的前三名 -\n");
printf("\t\t\t- 2.成绩输出 -\n");
printf("\t\t\t- (1)按学校编号输出 -\n");
printf("\t\t\t- (2)按学校总分输出 -\n");
printf("\t\t\t- (3)按男女团体输出 -\n");
printf("\t\t\t- 3.查询成绩 -\n");
printf("\t\t\t- (1)按学校编号查询各个项目 -\n");
printf("\t\t\t- (2)按项目编号查询前五学校 -\n");
printf("\t\t\t- 4.显示所有成绩 -\n");
printf("\t\t\t- 5.退出 -\n");
printf("\t\t\t……………………………………………………………………………………………………\n");

}

int main()
{
int intergalgrade[Schnum][Pronum] = { 0 }; //各个学校的积分成绩的存储
intzoom(Schnum,Pronum);
screen();
printf(“请输入以下信息:\n”);
calibrate();
printf(“信息录入完成!\n”);
printf(“正在进行学校项目成绩的录入:\n”);
for (int i = 0; i < Schnum; i++)
{
printf(“男子项目录入中……”);
schoolman();
printf(“女子项目录入中……”);
schoolwomen();
}
bubble_sort();
transition(intergalgrade);
Integral(intergalgrade);
backup();
mao(Schnum);
RT: screen(); // goto语句制造再次循环
printf(“请进行你的操作:\n”);
int a = 0;
int b = 0;
int d = 0;
char C = ‘0’;
int k1 = 0;
int k2 = 0;
scanf("%d", &a);
switch (a)
{
case 1:
printf(“正在进行操作:%d.\n”, a);
First_Rank();
break;
case 2:
printf(“正在进行操作:%d.\n”, a);
printf(“选择小操作项:\n”);
scanf("%d", &b);
switch (b)
{
case 1:
printf(“正在进行操作:%d.(%d)\n”, a, b);
PRINTF(b);
break;
case 2:
printf(“正在进行操作:%d.(%d)\n”, a, b);
PRINTF(b);
break;
case 3:
printf(“正在进行操作:%d.(%d)\n”, a, b);
PRINTF(b);
break;
default:
printf(“选择操作错误!!!\n”);
}
break;

case 3:
	printf("正在进行操作:%d.\n", a);
	printf("选择小操作项:\n");
	scanf("%d", &d);
	switch (d)
	{
	case 1:
		printf("正在进行操作:%d.(%d)\n", a, d);
		ask_for(d,intergalgrade);
		break;
	case 2:
		printf("正在进行操作:%d.(%d)\n", a, d);
		ask_for(d,intergalgrade);
		break;
	default:
		printf("选择操作错误!!!\n");
	}
	break;

case 4:
	printf("正在进行操作:%d.\n", a);
	allgrade(intergalgrade);
	break;
case 5:
	printf("正在进行操作:%d.\n", a);
	exit(0);
default:
	printf("选择操作错误!!!\n");
}

printf("如果想继续执行操作:Enter,输入其他的字符可结束操作。");
getchar();
scanf("%c", &C);
if (C == '\n')
{
	goto RT;
}
else
return 0;

}

//学校名字校准以及运动项目校准
void calibrate()
{
printf(“正在进行学校编码校准……\n”);
for (int i = 0; i < Schnum; i++)
{
printf(“此次输入学校编码:%d。\n”, i);
scanf("%s", school[i].schname);
}
printf(“正在进行运动项目编码校准……\n”);
for (int j = 0; j < Pronum; j++)
{
if (j < (Pronum / 2))
{
printf(“此次输入项目编码:%d(男子)。\n”, j);
}
else
{
printf(“此次输入项目编码:%d(女子)。\n”, j);
}
scanf("%s", project[j].proname);
}
}

//男子项目的成绩录入
void schoolman()
{
int a = 0, x = 0;
printf(“请选择学校编号(0-%d)(男子项目)。\n”, Schnum - 1);
scanf("%d", &a);
while (a < 0 ||a > Schnum - 1)
{
printf(“输入的学校编码错误!!!\n”);
scanf("%d", &a);
}
printf(“现在你正在进行学校:%s 编码:%d:男子项目录入\n”,school[a].schname ,a);
for (int m = 0; m < (Pronum/2); m++)
{
printf(“男子项目:%s 编码:%d:\n”,project[m].proname, m);
scanf("%d", &x);
school[a].prograde[m] = x;
school[a].cprograde[m] = x;
while (x < 0 || x > 100)
{
printf(“男子项目%d录入错误!!!请重新录入,成绩必须是0-100分。\n”, m);
scanf("%d", &x);
school[a].prograde[m] = x;
school[a].cprograde[m] = x;
}
printf(“录入成功!\n”);
}
}

//女子项目的成绩录入
void schoolwomen()
{
int a = 0, x = 0;
printf(“请选择学校编号(0-%d)(女子项目)。\n”, Schnum - 1);
scanf("%d", &a);
while (a < 0 || a > Schnum - 1)
{
printf(“输入的学校编码错误!!!\n”);
scanf("%d", &a);
}
printf(“现在你正在进行学校:%s 编码:%d:女子项目录入\n”, school[a].schname, a);
for (int m = (Pronum/2); m < Pronum; m++)
{
printf(“女子项目:%s 编码:%d:\n”, project[m].proname, m);
scanf("%d",&x);
school[a].prograde[m] = x;
school[a].cprograde[m] = x;
while (x < 0 || x > 100)
{
printf(“女子项目%d录入错误!!!请重新录入,成绩必须是0-100分。\n”, m);
scanf("%d", &x);
school[a].prograde[m] = x;
school[a].cprograde[m] = x;
}
printf(“录入成功!\n”);
}
}

//冒泡排序法 排出成绩的大小 排出初始数据的排名 进行连带同步名次排名 让高的分数先浮上来
void bubble_sort()
{
int temp = 0, temprank = 0;
for (int k = 0; k < Schnum; k++)
{
for (int i = 0; i < Pronum - 1; i++)
{
for (int j = 0; j < Schnum - 1 - i; j++)
{
if (school[j + 1].cprograde[k] > school[j].cprograde[k])
{
temp = school[j + 1].cprograde[k]; //copy的成绩进行排名
school[j + 1].cprograde[k] = school[j].cprograde[k];
school[j].cprograde[k] = temp;
temprank = school[j + 1].rank[k]; //随着同步排名把学校名次排进去
school[j + 1].rank[k] = school[j].rank[k];
school[j].rank[k] = temprank;
}
}
}
}
}

//名次转化成积分成绩
void transition(int intergalgrade[][Pronum])
{
for (int i = 0; i < Pronum; i++) //project
{
for (int j = 0; j < Schnum; j++) //school
{
int k = school[j].rank[i];
switch (j)
{
case 0:
intergalgrade[k][i] = 5; //积分赋值积分积分存储顺序不变
break;
case 1:
intergalgrade[k][i] = 3;
break;
case 2:
intergalgrade[k][i] = 2;
break;
default:
intergalgrade[k][i] = 0;
break;
}
}
}
}

//学校积分计算
void Integral(int intergalgrade[][Pronum])
{
for (int a = 0; a < Schnum; a++) //每个学校
{
for (int b = 0; b < Pronum; b++) // 总积分
{
school[a].Allgrade += intergalgrade[a][b];
}
for (int c = 0; c < (Pronum / 2); c++) // 男总积分
{
school[a].Boygrade += intergalgrade[a][c];
}
for (int d = (Pronum / 2); d < Pronum; d++) // 女总积分
{
school[a].Girlgrade += intergalgrade[a][d];
}
}
}

//原数据备份
void backup() //backup
{
for (int n = 0; n < Schnum; n++)
{
school[n].callgrade = school[n].Allgrade;
school[n].cboygrade = school[n].Boygrade;
school[n].cgirlgrade = school[n].Girlgrade;
}
}

// 反向冒泡排序
void mao(int n)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j <n- i; j++)
{
if (school[j].callgrade < school[j + 1].callgrade)
{
int temp = school[j].callgrade;
school[j].callgrade = school[j + 1].callgrade;
school[j + 1].callgrade = temp;

			int ranktemp = school[j].rankall;
			school[j].rankall = school[j + 1].rankall;
			school[j + 1].rankall = ranktemp;
		}
		if (school[j].cboygrade < school[j + 1].cboygrade)
		{
			int temp = school[j].cboygrade;
			school[j].cboygrade = school[j + 1].cboygrade;
			school[j + 1].cboygrade = temp;

			int ranktemp = school[j].rankboy;
			school[j].rankboy = school[j + 1].rankboy;
			school[j + 1].rankboy = ranktemp;
		}
		if (school[j].cgirlgrade < school[j + 1].cgirlgrade)
		{
			int temp = school[j].cgirlgrade;
			school[j].cgirlgrade = school[j + 1].cgirlgrade;
			school[j + 1].cgirlgrade = temp;

			int ranktemp = school[j].rankgirl;
			school[j].rankgirl = school[j + 1].rankgirl;
			school[j + 1].rankgirl = ranktemp;
		}
	}
}

}

//各个项目前五名输出
void First_Rank()
{
for (int j = 0; j < Pronum; j++)
{
int num = 1, rankgrade = 0;
printf(“项目%d排名结果如下:\n”, j);
for (int i = 0; i <N; i++)
{
switch (num)
{
case 1:
rankgrade = 5;
break;
case 2:
rankgrade = 3;
break;
case 3:
rankgrade = 2;
break;
default:
return;
}
printf(“第%d名,积分为%d分,学校:%s 编号为%d。\n”,num,rankgrade ,school[school[i].rank[j]].schname,school[i].rank[j]);
num++;
}
}
}

//每个学校各个项目的积分输出
void PRINTF(int bb)
{
switch (bb)
{
case 1:
for (int i = 0; i < Schnum; i++)
printf(“学校:%s 编号:%d\n总积分: %d分\n”,school[i].schname ,i, school[i].Allgrade);
break;
case 2:
printf(“总成绩:\n”);
for (int i = 0; i < Schnum; i++)
{
int k = 0;
k=school[i].rankall;
printf(“积分:%d分,学校名字:%s,学校编码:%d\n”, school[i].callgrade, school[k].schname, k);
}
printf("\n");
printf(“男子项目总成绩:\n”);
for (int i = 0; i < Schnum; i++)
{
int k = 0;
k=school[i].rankboy;
printf(“积分:%d分,学校名字:%s,学校编码:%d\n\n”, school[i].cboygrade, school[k].schname, k);
}
printf("\n");
printf(“女子项目总成绩:\n”);
for (int i = 0; i < Schnum; i++)
{
int k = 0;
k=school[i].rankgirl;
printf(“积分:%d分,学校名字%s,学校编码:%d\n\n”, school[i].cgirlgrade, school[k].schname, k);
}
break;
case 3:
for (int i = 0; i < Schnum; i++)
{
printf(“学校:%s 学校编号:%d\n男子总积分 :%d分\n”, school[i].schname, i, school[i].Boygrade);
printf(“学校:%s 学校编号:%d\n女子总积分: %d分\n”, school[i].schname, i, school[i].Girlgrade);
}
break;
}
}

//查询系统
void ask_for(int k,int intergalgrade[][Pronum])
{
if(k==1)
{
for (int n = 0; n < Schnum; n++)
{
if (n == k)
{
int g = 0;
printf(“请输入学校编号:”);
scanf("%d", &g);
printf(“学校编号:%d,学校名称:%s。\n”, g, school[g].schname);
for (int m = 0; m < Pronum; m++) //学校查询项目成绩
{
printf(“项目名称:%s,分数:%d分,原始成绩:%d。\n”, project[m].proname, intergalgrade[g][m], school[g].prograde[m]);
}
}
}
}
else
{
for (int m = 0; m < Pronum; m++)
{
if (m == k)
{
int g = 0;
printf(“请输入项目编号:”);
scanf("%d", &g);
int num = 1;
printf(“项目编号:%d,项目名称:%s。\n”, g, project[g].proname);
for (int n = 0; n < M; n++) //项目查询前五学校
{
int k = school[n].rank[g];
printf(“第%d名,学校名称:%s,分数:%d分。\n”, num, school[n].schname, intergalgrade[n][g]);
num++;
}
}
}
}
}

//全部显示
void allgrade(int intergalgrade[][Pronum])
{
FILE* fp;
fp = fopen(“Coursedesign.txt”, “w”);//追加写入
if (fp == NULL)
{
printf(“没有打开文件…\n”);
}
else
{
printf(“成功打开文件…\n”);
printf(“正在进入成绩录入系统…\n”);
}
Sleep(4000);
for (int n = 0; n < Schnum; n++)
{
printf(“学校:%s\n所有成绩如下:\n”,school[n].schname);
fprintf(fp, “学校:%s\n所有成绩如下:\n”, school[n].schname);
for (int m = 0; m < Pronum; m++)
{
printf(“原始数据:运动项目:%s,分数:%d。\n积分数据:运动项目:%s,积分:%d。\n”,project[m].proname,school[n].prograde[m], project[m].proname, intergalgrade[n][m]);
fprintf(fp,“原始数据:运动项目:%s,分数:%d。\n积分数据:运动项目:%s,积分:%d。\n”, project[m].proname, school[n].prograde[m], project[m].proname, intergalgrade[n][m]);
}
}
fclose(fp);
}

点击查看更多内容
0人点赞

若觉得本文不错,就分享一下吧!

评论

相关文章推荐

正在加载中
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消