作者brokenhand (我讨厌失眠的感觉)
看板Programming
标题Re: 请教c++的物件
时间Tue May 1 07:58:18 2007
※ 引述《[email protected] (帮我投票吧)》之铭言:
: 当我输入了箱子的长宽高之後
: 回应的体积为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