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

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

(考試時間: 13:10-13:50)

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

    int main()
    {
    double array[] = {1.0, 1.5, 2.0, 2.5, 3.0};
    char *stars[] = { "Catherine Zeta-Jones",
    "Angelina Jolie",
    "Nicolas Cage",
    "Sean Connery",
    "Arnold Schwarzenegger"
    };

    cout << sizeof array << "\t" << sizeof array[0] << endl;
    cout << sizeof stars << "\t" << sizeof stars[0] << 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;

    // This function returns a pointer to an integer

    int *max(int a, int b)
    {
    return (a>b) ? &a : &b;

    }

    int main()
    {
    cout << *max(3,5) << endl;
    cout << *max(10,1) << 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;

    void eat(char* str)
    {
    int i = 0, j = 0;
    while ((*(str + i) = *(str + j++)) != '\0')
    if (*(str + i) != ' ')
    i++;
    return;
    }

    int main(void)
    {
    char message[] = "TODAY IS WEDNESDAY.";
    eat(message);
    cout << message << endl;
    }