C++:输入长方体长宽高计算体积(使用构造函数)。

题目概述:
输入长方体长宽高计算体积。
编程:
#include
using namespace std;
class Cft
{
public:
Cft()
{
length = 0;
width = 0;
height = 0;
}
void set_CKG();
void show_V();
private:
float length;
float width;
float height;
};
void Cft::set_CKG()
{
cin >> length;
cin >> width;
cin >> height;
}
void Cft::show_V()
{
cout << “V=” << length * width * height << endl;
}
int main()
{
Cft s;
s.set_CKG();
s.show_V();
}
上机实践:
在这里插入图片描述

Guess you like

Origin blog.csdn.net/qq_50426849/article/details/120518139