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

科目名稱:程式設計 開課系所:資訊工程 學系 考試日期 2015.2.25
系所別:
年級:
學號:
姓名:
考試時間 10:30-10:40
  1. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Increment Operator (P.59)
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int a = 20;
        int b = 15;
        cout << a-- - --b << endl;
        return 0;
    }

  2. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Shorthand notation (P.58)
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int a = 144;
        int b =  12;
        int c =   6;
        a /= b + c;
        cout << a << endl;
        return 0;
    }

  3. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // Type Conversion (P.63)
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        float R = 2.0;
        cout << 3 / 2 * R * R << endl;
        cout << R * R * 3 / 2 << endl;
        return 0;
    }