C++ 判断两个立方体是否相等
生活随笔
收集整理的這篇文章主要介紹了
C++ 判断两个立方体是否相等
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用面向過程的方法:
#include <iostream>using namespace std;class Cube{private:int m_a;int m_b;int m_c;public://設置立方體的長寬高void setABC(int a, int b, int c){m_a = a;m_b = b;m_c = c;}int getA() {return m_a;}int getB() {return m_b;}int getC() {return m_c;} };//判斷兩個立方體是否相等 bool judge(Cube& c1, Cube& c2) {if (c1.getA() == c2.getA() &&c1.getB() == c2.getB() &&c1.getC() == c2.getC()) {return true;}else {return false;} }int main(void){Cube c1;c1.setABC(10, 20, 30);Cube c2;c2.setABC(10, 20, 30);// 面向過程的判斷方法if (judge(c1, c2) == true) {cout << "相同" << endl;}else {cout << "不同" << endl;} }使用面向對象的方法:
#include <iostream>using namespace std;class Cube{private:int m_a;int m_b;int m_c;public://設置立方體的長寬高void setABC(int a, int b, int c){m_a = a;m_b = b;m_c = c;}int getA() {return m_a;}int getB() {return m_b;}int getC() {return m_c;}//提供一個判斷兩個立方體是否相等的成員函數bool judge(Cube& another_c){if (m_a == another_c.m_a && // 同類之間無私處m_b == another_c.getB() &&m_c == another_c.getC()) {return true;} else {return false;}} };int main(void){Cube c1;c1.setABC(10, 20, 30);Cube c2;c2.setABC(10, 20, 30);//面向對象的判斷方法if (c1.judge(c2) == true) {cout << "相同" << endl;}else {cout << "不同" << endl;} } 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的C++ 判断两个立方体是否相等的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++ 椭圆类
- 下一篇: C++ 判断点是否在圆的内部