第三周 项目四 求三个长方柱的体积表面积

我的程序:


01./*  
02.* 程序的版权和版本声明部分:  
03.* Copyright (c) 2013, 烟台大学计算机学院  
04.* All rights reserved.  
05.* 文件名称:test.cpp  
06.* 作    者:王鲁峰  
07.* 完成日期:2014 年 3月 12日  
08.* 版 本 号:v1.0  
09.* 对任务及求解方法的描述部分: 
10.* 输入描述:无  
11.* 问题描述:求三个长方柱的体积表面积
12.* 程序输入:略 
13.* 程序输出:略
14.* 算法设计:略  
15.*/    
#include <iostream>
using namespace std;
class Bulk
{
public:
	void set_Bulk( );
	void show_Bulk( );


private:


	double length;
	double width;
	double heigth;
};
void Bulk::set_Bulk()
{
    cout<<"输入长方柱的长、宽、高:"<<endl;
    cin>>length>>width>>heigth;
}
void Bulk::show_Bulk()
{
    cout<<"长方柱的体积:"<<length*width*heigth<<endl;
    cout<<"长方柱的表面积:"<<2*(length*width+heigth*length+width*heigth)<<endl;
}
int main( )
{
	Bulk t1;
	t1.set_Bulk( );
	t1.show_Bulk( );
	Bulk t2;
	t2.set_Bulk( );
	t2.show_Bulk( );
	Bulk t3;
	t3.set_Bulk( );
	t3.show_Bulk( );
	return 0;
}


运行结果:


心得体会:

     从一个到多个运算,逐步取得成就感。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以回答这个问题。 首先,我们需要使用C++语言编写一个方体类。方体类应该具有度(length)、宽度(width)和高度(height)这三个成员变量,以及计算表面积体积的方法。 下面是一个简单的方体类示例: ```c++ class Cuboid { public: // 构造函数 Cuboid(double l, double w, double h) : length(l), width(w), height(h) {} // 计算表面积 double surface_area() const { return 2 * (length * width + length * height + width * height); } // 计算体积 double volume() const { return length * width * height; } // 判断两个方体是否相等 bool operator==(const Cuboid& other) const { return length == other.length && width == other.width && height == other.height; } private: double length; double width; double height; }; ``` 在这个示例中,我们定义了一个Cuboid类,并在构造函数中初始化了度、宽度和高度。然后,我们定义了计算表面积体积的两个方法,并使用运算符重载来判断两个方体是否相等。 现在,我们可以使用这个类来计算两个方体的表面积体积,并判断它们是否相等: ```c++ Cuboid cuboid1(2.0, 3.0, 4.0); Cuboid cuboid2(3.0, 4.0, 2.0); // 计算表面积体积 double surface_area1 = cuboid1.surface_area(); double volume1 = cuboid1.volume(); // 输出结果 std::cout << "Cuboid 1 surface area: " << surface_area1 << std::endl; std::cout << "Cuboid 1 volume: " << volume1 << std::endl; // 计算表面积体积 double surface_area2 = cuboid2.surface_area(); double volume2 = cuboid2.volume(); // 输出结果 std::cout << "Cuboid 2 surface area: " << surface_area2 << std::endl; std::cout << "Cuboid 2 volume: " << volume2 << std::endl; // 判断两个方体是否相等 if (cuboid1 == cuboid2) { std::cout << "The two cuboids are equal." << std::endl; } else { std::cout << "The two cuboids are not equal." << std::endl; } ``` 这段代码将输出两个方体的表面积体积,并判断它们是否相等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值