C++求长方柱体积

C++求长方柱体积,第1张

C++求长方柱体

【问题描述】有两个长方柱,其长、宽、高分别为:(1)30,20,10;(2)12,10,20。分别求他们的体积。编一个基于对象的程序,在类中用带参数的构造函数。

【输入形式】无
【输出形式】The volume of box1 is 6000

        The volume of box2 is 2400

【样例输入】空
【样例输出】

        The volume of box1 is 6000

        The volume of box2 is 2400

//长方柱体积
#include
using namespace std;
class box//建立长方柱的类 
{
	int c,k,g;
	public:
		box(int cc,int kk,int gg);
		int chang(){return c;}
		int kuan(){return k;}
		int gao(){return g;}
 };
 box::box(int cc,int kk,int gg)//构造函数 
 {
 	c=cc;k=kk;g=gg;//初始化长宽高 
 }
int main()
{
	box box1(30,20,10);
	box box2(12,10,20);//传入两个长方柱的数据 
	cout<<"The volume of box1 is "< 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5594608.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存