设计一个立方体类(Cube),属性值为长宽高(length,width,height)求立方体的面积和体积,写出无参和有参构造及析构函数,输出属性值函数,属性值设置和获取函数。

设计一个立方体类(Cube),属性值为长宽高(length,width,height)求立方体的面积和体积,写出无参和有参构造及析构函数,输出属性值函数,属性值设置和获取函数。不足之处,欢迎斧正。

​
#include<iostream>
using namespace std;
class Cube
{
	public:
		Cube(int l,int w,int h)
		{
			length=l;
			width=w;
			height=h;
		}
		Cube()
		{
			length=2;
			width=5;
			height=5;
		}
		void set_leng(int length)
		{}
		int get_leng()
		{	
		return length; 
		}
		void set_weig(int width)
		{}
		int get_weig()
		{	
		return width; 
		}
		void set_high(int height)
		{}
		int get_high()
		{	
		return height; 
		}
	/*	int culuateS()
		{
			return 2*(length*width+length*height+width*height);
		}
		int culuateV()
		{
			return length*width*height;
		 }                                                            */
		void print()
		{
		cout<<"立方体面积为:"<<2*(length*width+length*height+width*height)   <<"立方体体积为:"<< length*width*height<<endl; 
		 } 
	   ~Cube()
	   { 
	   }
	private:
		int length;
		int width;
		int height;		
 } ;
 int main()
 {
 	Cube c1(2,2,2);
 	Cube c2;
 	c1.print();
 	c2.print();
 	return 0;
 }

​

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猿动力

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值