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

科目名稱:程式設計 開課系所:資訊工程 學系 考試日期 2014.2.25
系所別:
年級:
學號:
姓名:
考試時間 18:10-18:20
  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.74)
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int a = 10;
        int b = 20;
        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.73)
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int a = 36;
        int b = 12;
        int c = 24;
        (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.78)
    #include <iostream>
    using std::cout;
    using std::endl;

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