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

科目名稱:程式設計 開課系所:資訊工程 學系 考試日期 2015.5.27
系所別:
年級:
學號:
姓名:
考試時間 08:20-08: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).
    // String Objects (P.405)
    #include <iostream>
    #include <string>
    using std::string;

    int main()
    {
        int m = 5;
        string n(m, 'n');
        std::cout << n << std::endl;
        return 0;
    }


  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).
    // Modifying Strings (P.410)
    #include <iostream>
    #include <string>
    using std::string;

    int main()
    {
        string a("Audrey Hepburn");
        string b(a, 0, 6);
        std::cout << b.replace(3,3,"i") << std::endl;
        return 0;
    }


  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).
    // Searching Strings (P.418)
    #include <iostream>
    #include <string>
    using std::string;

    int main()
    {
        string a("Audrey Hepburn");
        string b("e");
        std::cout << a.find(b) << a.find(b, 5) << std::endl;
        // string::npos = 18446744073709551615, which is 2^64 - 1.
        return 0;
    }