國立暨南國際大學 101 學年度第二學期小考試卷                   (考試時間: 14:10-14:20)
科目名稱:程式設計 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2013.3.5
  1. (10%) Determine whether the following code has syntax errors or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Access Control
    #include <iostream>

    class CBox           // Class definition at global scope
    {
    private:
        int m_Length;    // Length of a box in inches
        int m_Width;     // Width of a box in inches
        int m_Height;    // Height of a box in inches

        CBox(int lv, int wv, int hv)    // Constructor
        {
            m_Length = lv;
            m_Width = wv;
            m_Height = hv;
        }

        int Volume()
        {
            return m_Length * m_Width * m_Height;
        }
    };

    int main()
    {
      CBox box1(1, 2, 3);   // Declare box1 of type CBox
      std::cout << box1.Volume() << std::endl;
      return 0;
    }


  2. (10%) Determine whether the following code has syntax errors or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Copy Constructor
    #include <iostream>

    class CBox              // Class definition at global scope
    {
    public:
        int m_Length;       // Length of a box in inches
        int m_Width;        // Width of a box in inches
        int m_Height;       // Height of a box in inches

        CBox(int lv, int wv, int hv)    // Constructor
        {
            m_Length = lv;
            m_Width = wv;
            m_Height = hv;
        }

        CBox(const CBox& aBox)   // Copy Constructor
        {
            m_Length = aBox.m_Length;
            m_Width  = aBox.m_Width;
            m_Height = aBox.m_Height * 2;
        }

        int Volume()
        {
            return m_Length * m_Width * m_Height;
        }
    };

    int main()
    {
      CBox box1(1, 2, 3);     // Declare box1 of type CBox
      CBox box2 = box1;       // Declare box2 of type CBox
      std::cout << box2.Volume() << std::endl;
      return 0;
    }