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

科目名稱:程式設計 開課系所:資訊工程 學系 考試日期 2014.3.4
系所別:
年級:
學號:
姓名:
考試時間 14:10-14: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).
    // Comparing Values (P.122)
    #include <iostream>

    int main()
    {
        int a = 2;
        int b = 5;
        std::cout << (a == b) << (a = b) << std::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).
    // Conditional Operator (P.133)
    #include <iostream>

    int main()
    {
        int i;
        for (i=3; i<=6; i++)
            std::cout << ( i % 2 == 0 ? "Even" : "Odd" ) << std::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).
    // for Loop (P.140)
    #include <iostream>

    int main()
    {
        int i;
        for (i=1; i<=6; i++);
        {
            std::cout << i << std::endl;
        }
        return 0;
    }