为实现输入两个立方体的长宽高,通过计算来看其是否全等,我写了如下的程序:
#include<iostream>
using namespace std;
class Cube{
public:
void setcircle(int L,int W,int H){
int m_L = L;
int m_W = W;
int m_H = H;
}
int getlong(){
return m_L;
}
int getwide(){
return m_W;
}
int gethight(){
return m_H;
}
int area(){
return 2*(m_L * m_W + m_W * m_H + m_L * m_H);
}
int volume(){
return m_L * m_W * m_H;
}
private:
int m_L;
int m_W;
int m_H;
};
bool equalty(Cube first, Cube second){
if(first.area() == second.area() && first.volume() == second.volume()){
return true;
}
else return false;
};
int main()
{
Cube first;
int L1,W1,H1;
cin >> L1;
cin >> W1;
cin >> H1;
first.setcircle(L1,W1,H1);
Cube second;
int L2,W2,H2;
cin >> L2;
cin >> W2;
cin >> H2;
second.setcircle(L2,W2,H2);
cout << first.gethight() << endl;
cout << first.volume() << " " << second.volume() << endl;
cout << equalty(first,second) << endl;
system("pause");
return 0;
}
输入和输出的结果如下↓
很明显,输入的数据并不能写入相应的对象中,不知道哪里出了问题
非常感谢大家的帮助!
void setcircle(int L,int W,int H){
m_L = L;
m_W = W;
m_H = H;
}
这里前面的int去掉