國立暨南國際大學 101 學年度第二學期小考試卷                   (考試時間: 08:10-08:20)
科目名稱:程式設計 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2013.3.15
  1. (10%) Determine whether the following code has syntax errors or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // find() function for string
    #include <iostream>
    #include <string>

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

    int main()
    {
        string text = "ABCABC";
        string pattern = "BC";
        cout << text.find(pattern) << endl;
        cout << text.find(pattern, 3) << endl;
        return 0;
    }



  2. (10%) Determine whether the following code has syntax errors or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // insert() function for string
    #include <iostream>
    #include <string>

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

    int main()
    {
        string text = "ABCABC";
        string pattern = "BC";
        cout << text.insert(2,pattern) << endl;
        cout << text << endl;
        return 0;
    }