國立暨南國際大學 100 學年度第二學期小考試卷                   (考試時間: 16:50-17:00)
科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2012.4.11
  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).
    // Class Inheritance
    #include <iostream>

    class CBox
    {
    public:
    CBox(double lv = 1.0, double wv = 1.0, double hv = 1.0):
    m_Length(lv), m_Width(wv), m_Height(hv){}
    private:
    double m_Length;
    double m_Width;
    double m_Height;
    };

    class CCandyBox: CBox
    {
    public:
    char* m_Contents;

    // Function to calculate the volume of a CCandyBox object
    double Volume() const // Error - members not accessible
    { return m_Length*m_Width*m_Height; }

    CCandyBox(char* str = "Candy") // Constructor
    {
    m_Contents = new char[ strlen(str) + 1 ];
    strcpy_s(m_Contents, strlen(str)+1, str);
    }

    ~CCandyBox() // Destructor
    { delete[] m_Contents; };
    };

    int main()
    {
    CCandyBox aBox;
    std::cout << aBox.Volume() << std::endl;
    return 0;
    }