Re: 請教c++的物件

看板Programming作者 (我討厭失眠的感覺)時間18年前 (2007/05/01 07:58), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《quota@kkcity.com.tw (幫我投票吧)》之銘言: : 當我輸入了箱子的長寬高之後 : 回應的體積為0 : 請問我在物件的操作上 : 是否遺漏了什麼呢 : 附上原始程式,麻煩各位點醒我哪裡出錯 : 謝謝! : class CBox : { : private: : double m_Length; : double m_Breadth; : double m_Height; : public: : double Volume1(double a) : { : m_Length=a; : return m_Length; : } : double Volume2(double b) : { : m_Breadth=b; : return m_Breadth; : } : double Volume3(double c) : { : m_Height=c; : return m_Height; : } : double Volume() : { : return m_Length*m_Breadth*m_Height; : } : }; : #include <iostream> : using namespace std; : int main() : { : CBox box1; : double a1,b1,c1; : cout << endl : << "box1 長度= " << endl; : cin >> a1; : box1.Volume1(a1); ~~~~~~~~~~~~~設定m_Length : cout << endl : << "box1 寬度= " << endl; : cin >> b1; : box1.Volume1(b1); ~~~~~~~~~~~又設定m_Length 照程式看來你應該是要設m_Breadth,所以function name 你或許該打Volume2(b1) : cout << endl : << "box1 高度= " << endl; : cin >> c1; : box1.Volume1(c1); ~~~~~~~~~~~~~ 再設定一次m_Length,你應該是要設定m_Height 所以應該是要call Volume3(c1)才對 : cout << endl : << "Volume of box1 = " : << box1.Volume(); : cout << endl; : system("PAUSE"); : return 0; : } -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.71.10
文章代碼(AID): #16DeARnP (Programming)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #16DeARnP (Programming)