Re: 請教c++的物件
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章