#include<iostream>
#include<string>
using namespace std;
//class代表一个类,后面紧跟类名
class Cube
{
public:
void setm_l(int l)
{
m_l = l;
}
int getm_l()
{
return m_l;
}
void setm_w(int w)
{
m_w = w;
}
int getm_w()
{
return m_w;
}
void setm_h(int h)
{
m_h = h;
}
int getm_h()
{
return m_h;
}
int getS()
{
return 2 * (m_l*m_w + m_l*m_h + m_w*m_h);
}
int getV()
{
return m_l*m_h*m_w;
}
//利用成员函数判断两个立方体是否相等
bool issamebyclass(Cube &c)
{
if (m_h == c.getm_h() && m_l == c.getm_l() && m_w == c.getm_w())
return true;
return false;
}
private:
int m_l; //
int m_w; //
int m_h;//
};
//全局函数判断两个立方体是否相等
bool issame(Cube &c1, Cube &c2)
{
if (c1.getm_h() == c2.getm_h() && c1.getm_l() == c2.getm_l() && c1.getm_w() == c2.getm_w())
return true;
return false;
}
int main()
{
Cube c1;
c1.setm_l(1);
c1.setm_w(2);
c1.setm_h(3);
cout << "c1的面积为:" << c1.getS() << endl;
cout << "c1的体积为:" << c1.getV() << endl;
Cube c2;
c2.setm_l(1);
c2.setm_w(2);
c2.setm_h(3);
//全局函数判断是否相等
bool reet = issame(c1, c2);
if (reet)
{
cout << "c1和c2相等" << endl;
}
else
{
cout << "c1和c2不等" << endl;
}
Cube c3;
c3.setm_l(2);
c3.setm_w(2);
c3.setm_h(3);
//成员函数判断是否相等
bool ret = c1.issamebyclass(c3);
if (ret)
{
cout << "c1和c3相等" << endl;
}
else
{
cout << "c1和c3不等" << endl;
}
system("pause");
return 0;
}