國立暨南國際大學 99 學年度第二學期小考試卷

科目名稱:程式設計 開課系所:資訊工程學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2011.3.9

(考試時間: 14:10-14:20)


  1. (10%) 請問今天與大家分享參賽經驗的碩士班學長是:
    1. 林宣華
    2. 張育倫
    3. 王偉諠
    4. 杜迪榕

  2. (10%) 說明物件導向程式設計 (Object-Oriented Design) 過程中, 所會使用到哪些物件的 Class Diagram (類別圖), 會記載在軟體工程中的哪一份文件裡?
    1. 專案規劃書
    2. 需求說明文件
    3. 系統設計文件
    4. 測試報告
  3. (10%) Determine whether the following code has syntax erros or not.  If it is correct, predict its output.  If it is
    incorrect, point out the mistake(s).

    #include <iostream>
    using std::cout;
    using std::endl;

    class CRational
    {
    public:
    int numerator; // 分子
    int denominator; // 分母

    CRational(int p=0, int q=1)
    : numerator(p), denominator(q)
    {
    if (q==0)
    {
    cout << "Error! The denominator cannot be 0.\n";
    exit(1);
    }
    }

    void Print()
    {
    cout << numerator;
    if (denominator != 1)
    cout << "/" << denominator;
    cout << endl;
    }
    };

    int main()
    {
    CRational a;
    CRational b(3);
    CRational c(1,7);
    a.Print(); b.Print(); c.Print();
    return 0;
    }