//案例1:设计立方体类[cube],求出立方体的面积和体积;
// 求两个立方体,是否相等(全局函数和成员函数);
class MyCube1
{
public:
void setABC(double a,double b,double c) {
m_a = a;
m_b = b;
m_c = c;
}
double setA() {
return m_a;
}
double setB() {
return m_b;
}
double setC() {
return m_c;
}
public:
double getV() {
m_v = m_a * m_b*m_c;
return m_v;
}
double getS() {
m_s= 2 * (m_a*m_b + m_a * m_c + m_b * m_c);
return m_s;
}
int JudgeCube(MyCube1 &c2) {//开始用面向对象的思想方法去解决问题;
if (m_a == c2.setA() && m_b == c2.setB() && m_c == c2.setC() ){
return 1;
} //此时m_a属于c1,c2.setA()是出c2的;
else {
return 0;
}
}
private:
double m_a;
double m_b;
double m_c;
double m_v;
double m_s;
};
这个问题主要思想在于,类的成员函数:int JudgeCube(MyCube1 &am