代码:
#include<iostream>
using namespace std;
class Cube
{
public:
void setL(int l)
{
m_L = l;
}
int getL()
{
return m_L;
}
void setW(int w)
{
m_W = w;
}
int getW()
{
return m_W;
}
void setH(int h)
{
m_H = h;
}
int getH()
{
return m_H;
}
int calculateS()
{
return 2 * (m_L + m_W + m_H) ;
}
int calculateV()
{
return m_L * m_W * m_H ;
}
bool isSameByClass(Cube &c)
{
if (m_L == c.getL() && m_W == c.getW() && m_H == c.getH())
{
return true;
}
else
return false;
}
private:
int m_L;
int m_W;
int m_H;
};
bool isSane(Cube &c1, Cube &c2)
{
if (c1.getL() == c2.getL() && c1.getW() == c2.getW() && c1.getH() == c2.getH())
{
return true;
}
else
return false;
}
int main()
{
Cube c1;
c1.setL(1);
c1.setW(2);
c1.setH(3);
cout << "第一个立方体的长为:" << c1.getL() << endl;
cout << "第一个立方体的宽为:" << c1.getW() << endl;
cout << "第一个立方体的高为:" << c1.getH() << endl;
cout << "第一个立方体的面积为:" << c1.calculateS() << endl;
cout << "第一个立方体的体积为:" << c1.calculateV() << endl;
Cube c2;
c2.setL(1);
c2.setW(2);
c2.setH(3);
cout << "第二个立方体的长为:" << c2.getL() << endl;
cout << "第二个立方体的宽为:" << c2.getW() << endl;
cout << "第二个立方体的高为:" << c2.getH() << endl;
cout << "第二个立方体的面积为:" << c2.calculateS() << endl;
cout << "第二个立方体的体积为:" << c2.calculateV() << endl;
bool end1 = isSane(c1, c2);
if (end1)
{
cout << "相等" << endl;
}
else
cout << "不相等" << endl;
bool end2 = c1.isSameByClass(c2);
if (end2)
{
cout << "相等" << endl;
}
else
cout << "不相等" << endl;
system("pause");
return 0;
}