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

科目名稱:程式設計 開課系所:資訊工程學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2011.4.13

(考試時間: 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).

    #include <iostream>
    #include <string>
    using std::cout;
    using std::endl;
    using std::string;

    int main()
    {
    string proverb("A nod is as good as a wink to a blind horse");
    string sentence("It's bath time!");
    sentence.replace(5, 4, proverb, 12, 4);
    cout << sentence << endl;
    return 0;
    }




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

    #include <iostream>
    #include <string>
    using std::cout;
    using std::endl;
    using std::string;

    int main()
    {
    string school;
    string word("NCTU");
    school.append(2, 'N');
    school.insert(1, "C");
    school.insert(3, "U");
    cout << school << endl;
    school.swap(word);
    cout << word.find(school.at(0), 0) << endl;
    cout << word.find(school.at(1), 1) << endl;
    return 0;
    }