|
@@ -0,0 +1,132 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+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_H * m_W + 2 * m_L * m_H;
|
|
|
+ }
|
|
|
+
|
|
|
+ int calculateV()
|
|
|
+ {
|
|
|
+ return m_H * m_L * m_W;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ bool isSameByClass(Cube &c)
|
|
|
+ {
|
|
|
+ if (m_L == c.getL() && m_W == c.getW() && m_H == c.getH())
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+int main5()
|
|
|
+{
|
|
|
+
|
|
|
+ Cube c1;
|
|
|
+ c1.setL(10);
|
|
|
+ c1.setW(10);
|
|
|
+ c1.setH(10);
|
|
|
+
|
|
|
+ std::cout << "c1的面积为 : " << c1.calculateS() << std::endl;
|
|
|
+ std::cout << "c1的体积为 : " << c1.calculateV() << std::endl;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Cube c2;
|
|
|
+ c1.setL(10);
|
|
|
+ c1.setW(10);
|
|
|
+ c1.setH(10);
|
|
|
+
|
|
|
+
|
|
|
+ bool ret = isSame(c1, c2);
|
|
|
+ if (ret)
|
|
|
+ {
|
|
|
+ std::cout << "全局函数判断 : c1和c2是相等的" << std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ std::cout << "全局函数判断 : c1和c2是不相等的" << std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ ret = c1.isSameByClass(c2);
|
|
|
+ if (ret)
|
|
|
+ {
|
|
|
+ std::cout << "成员函数判断 : c1和c2是相等的" << std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ std::cout << "成员函数判断 : c1和c2是不相等的" << std::endl;
|
|
|
+
|
|
|
+ system("pause");
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|