#include<iostream>
#include<string>
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 +2*m_w* m_h+2*m_l*m_h;
}
int calculatev()
{
return m_l * m_w * m_h ;
}
bool issamebyclass(cube &c)
{
if (m_l == c.getl() && m_h == c.geth() && m_w == c.getw())
return true;
else return false;
}
private:
int m_l;
int m_w;
int m_h;
};
bool issame(cube& c1, cube& c2)//引用传递
{
if (c1.getl() == c2.getl() && c1.geth() == c2.geth() && c1.getw() == c2.getw())
return true;
else return false;
}
int main()
{
cube c1;
c1.seth(10);
c1.setl(10);
c1.setw(10);
cube c2;
c2.seth(10);
c2.setl(12);
c2.setw(10);
cout << "c1的面积为:" << c1.calculates() << endl;
cout << "c1的体积为:" << c1.calculatev() << endl;
bool ret=issame(c1,c2);
if (ret)
{
cout << "两个立方体相同" << endl;
}
else
cout << "两个个立方体不相同" << endl;
bool ret1 = c1.issamebyclass(c2);
if (ret1)
{
cout << "成员函数:这两个立方体相同" << endl;
}
else cout << "成员函数:两个立方体不同" << endl;
system("pause");
return 0;
}