用C++来实现绩点计算器

#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

double sum(double xuefen,double fenshu)
{
    if(fenshu < 60)
    {
        return 0;
    }
    return xuefen * (fenshu - 50) / 10;
}

double sumJiDian(vector<string> className,vector<double> classScore,vector<double> classFenShu)
{
    double temp1 = 0;
    double temp2 = 0;

    for (int i = 0; i < className.size();++i)
    {
        if(classFenShu[i] < 60)
        {
            continue;
        }
        temp1 += sum(classScore[i], classFenShu[i]);
        temp2 += classScore[i];
    }
    return temp1 / temp2;
}
int main()
{
    vector<string> className = {"网站设计与制作", "软件工程", "接口技术", "组成原理实验", "操作系统", "操作系统实验", "编译原理", "大学物理"};
    vector<double> classScore = {2, 2.5, 2, 1, 2, 1, 2, 2};
    vector<double> classFenShu = {0, 0, 0, 0, 0, 0, 0, 0};//换成对应分数就行

    double jidian = sumJiDian(className, classScore, classFenShu);
    cout << jidian << endl;
    return 0;
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页