编写一个程序,用同一函数名对圆、矩形和梯形求面积,参数自行设置,要求所有输入输出在主函数内进行。
3条回答 默认 最新
- threenewbee 2023-05-27 15:29关注
#include <iostream> using namespace std; // 函数名:Area(radius) // 参数:radius 圆的半径 // 返回值:圆的面积 double Area(double radius) { return 3.14 * radius * radius; } // 函数名:Area(width, height) // 参数:width 矩形的宽,height 矩形的高 // 返回值:矩形的面积 double Area(double width, double height) { return width * height; } // 函数名Area(width, height, depth) // 参数:width 梯形的上底,height 梯形的高,depth 梯形的下底 // 返回值:梯形的面积 double Area(double width, double height, double depth) { return (width * depth) * height / 2; } int main() { double radius, width, height; cout << "请输入圆的半径 (单位:米):"; cin >> radius; double area = Area(radius); cout << "圆的面积是:" << area << endl; double width, height; cout << "请输入矩形的宽和高 (单位:米):"; cin >> width >> height; double area = Area(width, height); cout << "矩形的面积是:" << area << endl; double depth, height, width; cout << "请输入梯形的上底、高和下底:"; cin >> depth >> height >> width; double area = Area(width, height, depth); cout << "梯形的面积是:" << area << endl; return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
- ¥15 计算决策面并仿真附上结果
- ¥20 halcon 图像拼接
- ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错
- ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
- ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
- ¥15 SPSS分类模型实训题步骤
- ¥100 求ASMedia ASM1184e & ASM1187e 芯片datasheet/规格书
- ¥15 求解决扩散模型代码问题
- ¥15 工创大赛太阳能电动车项目零基础要学什么