國立暨南國際大學 98 學年度第一學期小考試卷

 
科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2009.12.2

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

  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).

    // Matrix
    #include <iostream>

    using std::cout;
    using std::endl;

    int main()
    {
    int value[10] = { 1, 3, 5, 7, 9};
    int i = 0;

    for (i=0; i<10; i += 2)
    value[i] = i;

    cout << value[2] << "\t" << value[3] << endl;
    }





  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).
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
    char str1[10] = "NCNU";
    char str2[10];
    int i=0, j;
    while (str1[i] != '\0')
    i++;
    for (j=0, --i; i>=0; i--, j++)
    str2[j] = str1[i];
    str2[j] = '\0';
    cout << str1 << endl;
    cout << str2 << endl;
    }




  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).

    #include <iostream>

    using std::cout;
    using std::endl;

    int main()
    {
    int value = 10;
    int* pvalue = &value;
    value += 5;
    cout << value+*pvalue << endl;
    }



  4. (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).

    #include <iostream>

    using std::cout;
    using std::endl;

    int main()
    {
        char str[10] = "Basic";
        char* p = str;
        cout << str << endl;
        for ( ; *p != '\0'; p++)
            *p ^= 0x20;
        cout << str << endl;
    }