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

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

    int main()
    {
        int a = 3;
        int b = 4;
        std::cout << (a == b) << std::endl;
        std::cout << (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.103)
    #include <iostream>

    int main()
    {
        int i;
        for (i=4; i<=7; 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.110)
    #include <iostream>

    int main()
    {
        int i;
        for (i=3; i<=7; i+=2);
        {
            std::cout << i << std::endl;
        }
        return 0;
    }