HNU程序设计训练2023——绩点计算

该程序用于计算学生的总评绩点(GPA),基于给定的课程学分和实际得分,通过绩点转换函数将分数转化为绩点,然后加权平均得出GPA。输入包括课程数量、各课程学分和对应得分,输出为GPA值,保留两位小数。
摘要由CSDN通过智能技术生成

【问题描述】

学校对本科生的成绩施行绩点制(GPA)。将学生的实际考分根据不同学科的不同学分按一定的公式进行计算。规定如下:

实际成绩        绩点

90-100          4.0

85-89            3.7

82-84            3.3

78-81            3.0

75-77            2.7

72-74            2.3

68-71            2.0

64-67            1.5

60-63            1.0

60以下            0

1. 一门课程的学分绩点=该课绩点*该课学分

2. 总评绩点=所有学科绩点之和/所有课程学分之和

现要求你编程求出某人的总评绩点(GPA)

【输入形式】

第一行 总的课程数n

第二行 相应课程的学分(两个学分间用空格隔开)

第三行 对应课程的实际得分

此处输入的所有数字均为整数

【输出形式】

输出有一行,总评绩点,保留两位小数

【样例输入】

5
4 3 4 2 3
91 88 72 69 56

【样例输出】

2.52
#include <iostream>
#include <iomanip>
using namespace std;

struct GPA
{
	int score = 0;
	float gpa = 0;
	int weight = 0;
};
float conversion(int score)
{
	if (score >= 90) return 4.0;
	else if (score >= 85) return 3.7;
	else if (score >= 82) return 3.3;
	else if (score >= 78) return 3.0;
	else if (score >= 75) return 2.7;
	else if (score >= 72) return 2.3;
	else if (score >= 68) return 2.0;
	else if (score >= 64) return 1.5;
	else if (score >= 60) return 1.0;
	else return 0;
}
int main()
{
	int n = 0;
	cin >> n;
	GPA* a = new GPA[n];
	float W = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].weight;
		W += a[i].weight;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].score;
	}
	float sum = 0;
	for (int i = 0; i < n; i++)
	{
		sum+=a[i].weight*conversion(a[i].score);
	}
	cout <<fixed<<setprecision(2)<< sum / W;
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值