- 需要求解3个长方体,请编程实现一个基于对象的程序。数据成员有length(长)、width(宽)、height(高)。要求用成员函数实现以下功能: a) 由键盘输入3个长方体的长、宽、高 b) 计算3个长方体的体积。 c) 输出3个长方体的体积。 请编写程序,上机运行。
求帮忙C++程序,大佬们求答案?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 小優YoU 2017-12-05 08:32关注
用class实现,,讲道理,你还是看书打好面向对象基础再说。。这种题真是基本中的基本。。。
#include <iostream> using namespace std; class Rectangle { public: Rectangle(double length, double width, double height) { this->length = length; this->width = width; this->height = height; } double toVolume(void) { this->volume = length * width * height; return volume; } private: double length; double width; double height; double volume; }; int main(void) { double length, width, height; cin >> length >> width >> height; Rectangle* rectangle = new Rectangle(length, width, height); double volume = rectangle->toVolume(); delete rectangle; cout << volume << endl; system("pause"); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥17 pro*C预编译“闪回查询”报错SCN不能识别
- ¥15 微信会员卡接入微信支付商户号收款
- ¥15 如何获取烟草零售终端数据
- ¥15 数学建模招标中位数问题
- ¥15 phython路径名过长报错 不知道什么问题
- ¥15 深度学习中模型转换该怎么实现
- ¥15 HLs设计手写数字识别程序编译通不过
- ¥15 Stata外部命令安装问题求帮助!
- ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
- ¥15 TYPCE母转母,插入认方向