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

    class CBox
    {
    public:
    int m_Length;
    int m_Width;
    int m_Height;

    CBox(int lv = 1, int wv = 2, int hv = 3): m_Length(lv), m_Width(wv), m_Height(hv) {}
    int Volumn() { return m_Length * m_Width * m_Height; }
    };

    class CCandyBox: public CBox
    {
    public:
    char m_Contents[12];
    CCandyBox(const char *str = "Candy")
    {
    strcpy(m_Contents, str);
    }
    };

    int main()
    {
    CCandyBox myCandyBox("Chocolate");
    std::cout << sizeof(CBox) << std::endl;
    std::cout << sizeof(myCandyBox) << 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).
    // protected
    #include <iostream>

    class CBox
    {
    protected:
    int m_Length;
    int m_Width;
    int m_Height;

    CBox(int lv = 1, int wv = 2, int hv = 3): m_Length(lv), m_Width(wv), m_Height(hv) {}
    int Volumn() { return m_Length * m_Width * m_Height; }
    };

    class CCandyBox: public CBox
    {
    protected:
    char m_Contents[12];
    public:
    CCandyBox(const char *str = "Candy")
    {
    strcpy(m_Contents, str);
    std::cout << "Construct a CandyBox " << str << " with volume "
    << m_Length * m_Width * m_Height << std::endl;
    }
    };

    int main()
    {
    CCandyBox myCandyBox("Chocolate");
    return 0;
    }