简单计算体侧成绩的小代码

背景:

数据库实验课,做完任务后没事情可做,看了自己的体测成绩,就想着敲一个小代码,太菜了,在机房没完成。今天算是完成了。

这里参考的是 《国家学生体质健康标准(2014年修订)》测试项目与权重表(点击打开链接)。

一些小技巧:

把网页数据导入 Excel ,提取列之后利用 word 处理为数据格式......

Bata:

1.0 2017年5月23日21:27:41 有 bug 敬请指出。

测试环境:DEV C++ 5.9.2

直接代码:

codeing 

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#define In(data) scanf("%lf", &data)
const int len = 32;

//当前测试项可以得到的分数
double GetScore[len] = {0, 100, 95, 90, 85, 80, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 50, 40, 30, 20, 10};
double val[] = {0, 0.15, 0.15, 0.2, 0.1, 0.1, 0.1, 0.2};//各个测试项权值

double NowScore(double boys[], double grils[], char Gender[], double s);
double BMI(char Gender[], double Height, double Weight); //1 体重指数(BMI)
double LungCapacity(char Gender[], double s); //2 肺活量
double KmRun(char Gender[], double s); //3 1000米跑(男)/800米跑(女)
double StandingLongJump(char Gender[], double s); //4 立定跳远
double SitAndReach(char Gender[], double s); //5 坐位体前屈
double ExclusiveBoy(double s); //6 引体向上(男)/一分钟仰卧起坐(女)
double ExclusiveGril(double s); //
double CmRun(char Gender[], double s); //7 50米跑
void Print(char Gender[], double Data[], double Ans[]);//输出结果

int main()
{
	double Data[8];//存储键入的数据项
	char Gender[8];//性别
	double Ans[8];//计算后的数据

	puts("依据《国家学生体质健康标准(2014年修订)》测试项目与权重表");

	printf("男子汉请键入' b ',萌妹子键入' g ',请键入性别:");
	scanf("%s", Gender);
	while(1) {
		if(Gender[0] == 'b' || Gender[0] == 'g') break;
		printf("输入有误,请检查后重新键入:");
		scanf("%s", Gender);
	}
	
	system("cls");
	printf("请键入你的身高(cm)和体重(kg),数据依空格隔开:");
	In(Data[0]), In(Data[1]);
	Ans[1] = BMI(Gender, Data[0], Data[1]);

	system("cls");
	printf("请键入你的肺活量数据:");
	In(Data[2]);
	Ans[2] =  LungCapacity(Gender, Data[2]);

	system("cls");
	int mm, ss;
	printf("请键入你的长跑数据(格式:mm.ss):");
	scanf("%d.%d", &mm, &ss);
	Data[3] = mm * 60.0 + ss * 1.0;
	Ans[3] = KmRun(Gender, Data[3]);

	system("cls");
	printf("请键入你的立定跳远数据(单位: cm):");
	In(Data[4]);
	Ans[4] = StandingLongJump(Gender, Data[4]);

	system("cls");
	printf("请键入你的坐位体前屈数据:");
	In(Data[5]);
	Ans[5] = SitAndReach(Gender, Data[5]);

	system("cls");
	if(Gender[0]== 'b') {
		printf("请键入你的引体向上数据:");
		In(Data[6]);
		Ans[6] = ExclusiveBoy(Data[6]);
	} else {
		printf("请键入你的仰卧起坐数据:");
		In(Data[6]);
		Ans[6] = ExclusiveGril(Data[6]);
	}

	system("cls");
	printf("请键入你的50米短跑数据(输入格式mm.ss):");
	In(Data[7]);
	Ans[7] = CmRun(Gender, Data[7]);

	system("cls");
	double SumScore = 0;//总分数
	for(int i = 1; i <= 7; i++) {
		SumScore += (Ans[i] * val[i]);
	}
	Print(Gender, Data, Ans);
	printf("总成绩: %.2lf\n", SumScore);
	system("pause");
	return 0;
}

double NowScore(double boys[], double grils[], char Gender[], double s)
{
	double *p;
	double get;

	if(Gender[0] == 'b') {
		p = &boys[0];
	} else {
		p = &grils[0];
	}

	if(s < *(p+20)) get = 0;
	else if(s < *(p+19)) get = GetScore[20];
	else if(s < *(p+18)) get = GetScore[19];
	else if(s < *(p+17)) get = GetScore[18];
	else if(s < *(p+16)) get = GetScore[17];
	else if(s < *(p+15)) get = GetScore[16];
	else if(s < *(p+14)) get = GetScore[15];
	else if(s < *(p+13)) get = GetScore[14];
	else if(s < *(p+12)) get = GetScore[13];
	else if(s < *(p+11)) get = GetScore[12];
	else if(s < *(p+10)) get = GetScore[11];
	else if(s < *(p+9)) get = GetScore[10];
	else if(s < *(p+8)) get = GetScore[9];
	else if(s < *(p+7)) get = GetScore[8];
	else if(s < *(p+6)) get = GetScore[7];
	else if(s < *(p+5)) get = GetScore[6];
	else if(s < *(p+4)) get = GetScore[5];
	else if(s < *(p+3)) get = GetScore[4];
	else if(s < *(p+2)) get = GetScore[3];
	else if(s < *(p+1)) get = GetScore[2];
	else get = GetScore[1];
	return get;
}

double BMI(char Gender[], double Height, double Weight) //体重指数
{
	double get = 0, h = Height/100.0;
	double tmp = Weight / (h * h);
	if(Gender[0] == 'b') {
		if(tmp >= 28.0) get = 60;
		else if(tmp >= 17.9 && tmp <= 23.9) get = 100;
		else get = 80;
	} else {
		if(tmp >= 28.0) get = 60;
		else if(tmp >= 17.2 && tmp <= 23.9) get = 100;
		else get = 80;
	}
	return get;
}

double LungCapacity(char Gender[], double s) //肺活量
{
	double boys[len] = {0, 5040, 4920, 4800, 4550, 4300, 4180, 4060, 3940, 3820, 3700, 3580, 3460, 3340, 3220, 3100, 2940, 2780, 2620, 2460, 2300};
	double grils[len] = {0, 3400, 3350, 3300, 3150, 3000, 2900, 2800, 2700, 2600, 2500, 2400, 2300, 2200, 2100, 2000, 1960, 1920, 1880, 1840, 1800};

	return NowScore(boys, grils, Gender, s);
}

double CmRun(char Gender[], double s) //50米跑
{
	double boys[len] = {0, 6.7, 6.8, 6.9, 7, 7.1, 7.3, 7.5, 7.7, 7.9, 8.1, 8.3, 8.5, 8.7, 8.9, 9.1, 9.3, 9.5, 9.7, 9.9, 10.1};
	double grils[len] = {0, 7.5, 7.6, 7.7, 8, 8.3, 8.5, 8.7, 8.9, 9.1, 9.3, 9.5, 9.7, 9.9, 10.1, 10.3, 10.5, 10.7, 10.9, 11.1, 11.3};

	int getq;
	if(Gender[0] == 'b') {
		for(int i = 1; i <= 20; i++)
			if(s <= boys[i] && s >= boys[i-1]) {
				getq = i;
				break;
			}
	} else {
		for(int i = 1; i <= 20; i++)
			if(s <= grils[i] && s >= grils[i-1]) {
				getq = i;
				break;
			}
	}
	return GetScore[getq];
}

double SitAndReach(char Gender[], double s) //坐位体前屈
{
	double boys[len] = {0, 24.9, 23.1, 21.3, 19.5, 17.7, 16.3, 14.9, 13.5, 12.1, 10.7, 9.3, 7.9, 6.5, 5.1, 3.7, 2.7, 1.7, 0.7, -0.3, -1.3};
	double grils[len] = {0, 25.8, 24, 22.2, 20.6, 19, 17.7, 16.4, 15.1, 13.8, 12.5, 11.2, 9.9, 8.6, 7.3, 6, 5.2, 4.4, 3.6, 2.8, 2};

	return NowScore(boys, grils, Gender, s);
}

double StandingLongJump(char Gender[], double s) //立定跳远
{
	double boys[len] = {0, 273, 268, 263, 256, 248, 244, 240, 236, 232, 228, 224, 220, 216, 212, 208, 203, 198, 193, 188, 183};
	double grils[len] = {0, 207, 201, 195, 188, 181, 178, 175, 172, 169, 166, 163, 160, 157, 154, 151, 146, 141, 136, 131, 126};

	return NowScore(boys, grils, Gender, s);
}

double ExclusiveBoy(double s) //男生引体向上
{
	double boys[len] = {0, 19, 18, 17, 16, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 7, 6, 5};
	double grils[len] = {0};
	char Gender[] = "boy";

	return NowScore(boys, grils, Gender, s);
}

double ExclusiveGril(double s) //女生仰卧起坐
{

	double grils[len] = {0, 56, 54, 52, 49, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22, 20, 18, 16};
	double boys[len] = {0, 19, 18, 17, 16, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 7, 6, 5};

	char Gender[] = "gril";

	return NowScore(boys, grils, Gender, s);
}

double KmRun(char Gender[], double s) //女生800 m && 男生 1000 m
{
	int getq;
	double boys[len] = {0, 197, 202, 207, 214, 222, 227, 232, 237, 242, 247, 252, 257, 262, 267, 272, 292, 312, 332, 352, 372};
	double grils[len] = {0, 198, 204, 210, 217, 224, 229, 234, 239, 244, 249, 254, 259, 264, 269, 274, 284, 294, 304, 314, 324};
	if(Gender[0] == 'b') {
		for(int i = 1; i <= 20; i++)
			if(s <= boys[i] && s >= boys[i-1]) {
				getq = i;
				break;
			}
	} else {
		for(int i = 1; i <= 20; i++)
			if(s <= grils[i] && s >= grils[i-1]) {
				getq = i;
				break;
			}
	}
	return GetScore[getq];
}

void Print(char Gender[], double Data[], double Ans[])
{
	if(Gender[0] == 'b') puts("你是 boy ");
	else puts("你是 gril ");

	int i = 1;
	printf("测试项目\t数据\t成绩\t权重\t分数\n");
	printf("体重指数\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", Data[i], Ans[i], val[i], Ans[i] * val[i]);
	i = 2, printf("肺活量\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", Data[i], Ans[i], val[i], Ans[i] * val[i]);
	i = 3, printf("长跑\t\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", Data[i], Ans[i], val[i], Ans[i] * val[i]);
	i = 4, printf("立定跳远\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", Data[i], Ans[i], val[i], Ans[i] * val[i]);
	i = 5, printf("体前屈\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", Data[i], Ans[i], val[i], Ans[i] * val[i]);
	i = 6;
	if(Gender[0] == 'b') printf("引体向上\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", Data[i], Ans[i], val[i], Ans[i] * val[i]);
	else printf("仰卧起坐\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", Data[i], Ans[i], val[i], Ans[i] * val[i]);
	i = 7, printf("50米短跑\t%.2lf\t%.2lf\t%.2lf\t%.2lf\n", Data[i], Ans[i], val[i], Ans[i] * val[i]);
}


©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值