- (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.510)
#include
<iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
int a = 5;
string b(a);
cout << b << endl;
return 0;
}
- (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.523)
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main()
{
string a("NCNU");
string b("N");
cout << a.find(b) << a.find(b, 2)
<< endl;
return 0;
}
- (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).
// 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 = 5;
int c = 27;
cout << a.size() << endl;
a.push_back(b);
a.push_back(c);
cout << a.size() << endl;
return 0;
}