#include<iostream>
using namespace std;

double bottomarea(double r){
    //计算圆柱体的底面积
    return 3.14 * r * r;
}

double volume(double r, double h){
    //调用底面积函数,计算圆柱体的体积
    return bottomarea(r) * h;
}

double surarea(double r, double h){
    //计算圆柱体的表面积
    return 2 * 3.14 * r * h + 2 * bottomarea(r);
}

int main(){
    double r, h;
    cout << "请输入圆柱体的半径和高:";
    cin >> r >> h;
    cout << "圆柱体的体积为:" << volume(r, h) << endl;
    cout << "圆柱体的表面积为:" << surarea(r, h) << endl;
    return 0;
}
``
用C++写一串代码:在主函数中输入圆柱体的高和半径分别调用函数求圆柱体的体积和表面积。要求求体积时嵌套调用求底面积的函数。函数原型分别为:double volumedouble r;double h;double bottomareadouble r;double surareadouble r;double h;

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

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