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

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

Open book; turn off computer & mobile phone                    (考試時間: 16:30-16:45)

  1. (10%) Determine whether the following code has syntax erros or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).

    // Ex5_02.cpp
    // A futile attempt to modify caller arguments
    #include <iostream>
    using std::cout;

    int incr10(int num);           // Function prototype

    int main(void)
    {
       int num(3);

       cout << '\n' << "incr10(num) = " << incr10(num) << '\n'
            << "num = " << num << '\n';
       return 0;
    }

    // Function to increment a variable by 10
    int incr10(int num)            // Using the same name might help...
    {
       num += 10;                  // Increment the caller argument
       cout << "In the function, num = " << num << '\n';
       return num;                 // Return the incremented value
    }

  2. (10%) Determine
    whether the following code has syntax erros or not.  If it is correct,
    predict its output.  If it is incorrect, point out the mistake(s).
    // void function
    #include <iostream>
    using std::cout;

    void print_stars(int n);

    int main()
    {
    int j;
    for (j=5; j>1; j--)
    print_stars(j);
    return 0;
    }

    void print_stars(int n)
    {
    int i;
    for (i=0; i<n; i++)
    cout << "*";
    cout << '\n';
    return;
    }