#include <iostream>
#include <stdio.h>
#include <string>
#include <ctime>
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 ((C.getL() == m_L) && (C.getW() == m_W) && (C.getH() == m_H))
{
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.getW() == C2.getW()) && (C1.getH() == C2.getH()))
{
return true;
}
else
return false;
}
int main() {
class Cube c1, c2;
c1.setL(10);
c1.setW(10);
c1.setH(10);
c2.setL(10);
c2.setW(15);
c2.setH(10);
bool rel = c1.isSameByClass(c2);
bool rel = isSame(c1, c2);
if (rel) {
cout << "相等" << endl;
}
else {
cout << "不相等" << endl;
}
/*cout << "c1的面积为" << c1.calculateS() << endl;
cout << "c1的体积为" << c1.calculateV() << endl;*/
system("pause");
return 0;
}