#include <iostream>

double heightPredict(double faHeight, double moHeight, char gender) {
    double predictHeight;
    if (gender == 'M') {
        predictHeight = (faHeight + moHeight) * 0.54;
    } else if (gender == 'F') {
        predictHeight = (faHeight * 0.923 + moHeight) / 2;
    } else {
        std::cout << "Invalid gender!" << std::endl;
        return -1; // 返回-1表示性别参数无效
    }
    return predictHeight;
}

int main() {
    double fatherHeight, motherHeight;
    char gender;

    std::cout << "Enter father's height (in meters): ";
    std::cin >> fatherHeight;

    std::cout << "Enter mother's height (in meters): ";
    std::cin >> motherHeight;

    std::cout << "Enter gender (M/F): ";
    std::cin >> gender;

    double predictedHeight = heightPredict(fatherHeight, motherHeight, gender);
    if (predictedHeight != -1) {
        std::cout << "Predicted height: " << predictedHeight << " meters" << std::endl;
    }

    return 0;
}
``
编程语言:cpp题目:在不考虑后天因素影响的情况下成年人的身高可以基于其父母亲的身高有下面的身高预测公式:男性成人时身高 = 父亲身高 + 母亲身高 054女性成人时身高 = 父亲身高 0923 + 母亲身高 2请上述公式完成如下的身高预测函数功能:heightPredictdouble faHeight double moHeight char gender其中参数faHeight和moH

原文地址: http://www.cveoy.top/t/topic/hJmL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录