#include<iostream>
class cube
{
public:
void seth(int h)
{
m_h = h;
}
int geth()
{
return m_h;
}
void setw(int w)
{
m_w = w;
}
int getw()
{
return m_w;
}
void setl(int l)
{
m_l = l;
}
int getl()
{
return m_l;
}
int caculateS()
{
return m_h * m_w * 2 + m_l * m_w * 2 + m_h * m_l * 2;
}
int caculateV()
{
return m_h * m_l * m_w;
}
bool isSameinclass(cube& c)
{
if (m_l == c.getl() && m_w == c.getw() && m_h == c.geth())
return true;
else
return false;
}
private:
int m_h;
int m_w;
int m_l;
};
bool isSame(cube& c1, cube& c2)
{
if (c1.getl() == c2.getl() && c1.getw() == c2.getw() && c1.geth() == c2.geth())
return true;
return false;
}
int main()
{
cube c1, c2;
c1.seth(10);
c1.setl(10);
c1.setw(10);
std::cout << "表面积为:" << c1.caculateS() << std::endl;
c2.seth(10);
c2.setl(10);
c2.setw(10);
std::cout << "体积为:" << c1.caculateV() << std::endl;
if (isSame(c1, c2))
std::cout << "相等" << std::endl;
else
std::cout << "不相等" << std::endl;
if (c1.isSameinclass(c2))
std::cout << "相等a" << std::endl;
else
std::cout << "不相等a" << std::endl;
return 0;
}
c++中的类的学习
最新推荐文章于 2024-08-30 16:00:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)