判断两个立方体是否相等(类与对象实现)

#include<iostream>
using namespace std;

class Cube
{
public:
	void setacb(int a, int b, int c)
	{
		m_a = a;
		m_b = b;
		m_c = c;
	}
	int getabc()
	{
		return (m_a*m_b) * 2 + (m_a*m_b) * 2 + (m_b*m_c) * 2;
	}
	
	int getlume()
	{
		return (m_a*m_b*m_c);
	}

	int getA()
	{
		return m_a;
	}
	int getB()
	{
		return m_b;
	}
	int getC()
	{
		return m_c;
	} 

	bool judgeCube(Cube &another)
	{
		if (m_a == another.getA() &&
			m_b == another.getB() &&
			m_c == another.getC())
		{
			return true;
		}
		else
		{
			false;
		}
	}
private:
	int m_a;
	int m_b;
	int m_c;
};
bool judeCube(Cube &c1, Cube c2)
{
	if (c1.getA() == c2.getA() &&
		c1.getB() == c2.getB() &&
		c1.getC() == c2.getC())
	{
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
	Cube c1;
	c1.setacb(10, 20, 30);

	Cube c2;
	c2.setacb(10, 20, 30);

	cout << "c1体积是" << c1.getlume() << endl;
	cout << "c1体积是" << c1.getabc() << endl;
	if (judeCube(c1, c2)==true)
	{
		cout << "相等" << endl;
	}
	else
	{
		cout << "不相等" << endl;
	}


	cout << "----------" << endl;


	if (c1.judgeCube(c2) == true)
	{
		cout << "相等" << endl;
	}
	else
	{
		cout << "不相等" << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/chen_zan_yu_/article/details/88527982