科目名稱:程式設計 | 開課系所:資訊工程 學系 | 考試日期 | 2014.6.3 | ||
系所別: |
年級: |
學號: |
姓名: |
考試時間 | 14:10-16:00 |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 |
(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).
// String Objects (P.510)
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
int a = 6;
string b("B");
string c(a, 'b');
string d( c + b );
cout << c << endl;
cout << d << endl;
return 0;
}
(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).
// Searching Strings (P.523)
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
string a("NNNU");
string b("N");
cout << a.find(b) << a.find(b, 2) << endl;
return 0;
}
// The Size of a Vector (P.655)
#include <iostream>
#include <string>
#include <vector>
using std::cout;
using std::endl;
using std::string;
using std::vector;
int main()
{
vector<string> a;
int b = 6;
int c = 3;
cout << a.size() << endl;
a.push_back(b);
a.push_back(c);
cout << a.size() << endl;
return 0;
}