C++_用类的方法编程程序完成求3个长方体的体积。

Posted CaoPengCheng&

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++_用类的方法编程程序完成求3个长方体的体积。相关的知识,希望对你有一定的参考价值。

C++_用类的方法编程程序完成求3个长方体的体积。

#include<iostream>
using namespace std;
/**
 * 用类的方法编程程序完成求3个长方体的体积。数据成员包括长(length)、宽(width)、高(length)。
 * @author CaoPengCheng
 * @date 2021-10-09
 */

class Box{
private:
	int length;
	int width;
	int high;
public:
	void setData();
	int volume();
};
#include<iostream>
#include "2_2_Box.h"
using namespace std;
/**
 * 用类的方法编程程序完成求3个长方体的体积。数据成员包括长(length)、宽(width)、高(length)。
 * @author CaoPengCheng
 * @date 2021-10-09
 */

void Box::setData(){
	cout<<"input length:";
	cin>>length;
	cout<<"input width:";
	cin>>width;
	cout<<"input high:";
	cin>>high;
}

int Box::volume(){
	return length*width*high;
}
#include<iostream>
#include "2_2_Box.h"
using namespace std;
/**
 * 用类的方法编程程序完成求3个长方体的体积。数据成员包括长(length)、宽(width)、高(length)。
 * @author CaoPengCheng
 * @date 2021-10-09
 */

int main(){
	Box b1,b2,b3;
	b1.setData();
	cout<<"体积="<<b1.volume()<<endl<<endl;
	b2.setData();
	cout<<"体积="<<b2.volume()<<endl<<endl;
	b3.setData();
	cout<<"体积="<<b3.volume()<<endl;
}

以上是关于C++_用类的方法编程程序完成求3个长方体的体积。的主要内容,如果未能解决你的问题,请参考以下文章