Which changes introduced independently will allow the code to compile and display "one"
"eight" "nine" "ten"? Choose all that apply.
#include <iostream>
# include <map>
# include <string>
using namespace std;
class A {
int a;
public:
A(int a):a(a){}
int getA() const { return a;}
/* Insert Code Here 1 */
};
/* Insert Code Here 2 */
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
string s[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","ten"}; multimap<A,string> m;/* Replace Code Here 3 */
for(int i=0; i<10; i++) {
m.insert(pair<A,string>(A(t[i]),s[i]));
}
m.erase(m.lower_bound(2),m.upper_bound(7));
multimap<A, string>::iterator i=m.begin();/* Replace Code Here 4 */
for( ; i!= m.end(); i++) {
cout<<i?>second<<" ";
}
cout<<endl;
return 0;
}
A. bool operator < (const A & b) const { return b.a<a;} inserted at Place 1
B. bool operator < (const A & b) const { return a<b.a;} inserted at Place 1
C. struct R { bool operator ()(const A & a, const A & b) { return a.getA()<b.getA();} }; inserted at Place 2
replacing line marked 3 with multimap<A, string, R> m;
replacong line marked 4 with multimap<A, string, R>::iterator i=m.begin();
D. operator int() const { return a;} inserted at Place 1
正解:B,C,D
質問 2:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout<<100<<" ";
cout.flags(ios::showbase);
cout<<100<<" ";
return 0;
}
Program outputs:
A. compilation error
B. 64 100
C. 64 64
D. 0x64 0x64
E. 64 0x64
正解:B
質問 3:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main () {
int t[] = {1,2,3,4,5,1,2,3,5,4};
vector<int> v (t,t+10);
vector<int>::iterator it;
int m1[] = {1, 3, 2};
it = find_end (v.begin(), v.end(), m1, m1+3);
if (it != v.end())
cout << "Found at position: " << it?v.begin() << endl;
return 0;
}
A. program outputs: Found at position: 10
B. no output
C. program outputs: Found at position: 0
D. program outputs: Found at position: 5
正解:B
質問 4:
What happens when you attempt to compile and run the following code?
# include <list>
# include <vector>
# include <iostream>
using namespace std;
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5};
vector<int>v1(t, t+5);
list<int>l1;
l1.assign(v1.end(), v1.begin());
for(int i=0; i<l1.size(); i++)
{
cout<<l1.at(i)<<" ";
}
cout<<endl;
return 0;
}
A. compilation error
B. segmentation fault runtime exception
C. program displays 5 4 3 2 1
D. program displays 1 2 3 4 5
正解:A
質問 5:
What happens when you attempt to compile and run the following code?
# include <iostream>
# include <map>
# include <vector>
# include <sstream>
# include <string>
using namespace std;
int main(){
int t[] ={ 3, 4, 2, 1, 0, 1, 2, 3, 4, 0 };
vector<int> v(t, t+10);
multimap<int,string> m;
for(vector<int>::iterator i=v.begin(); i!=v.end(); i++) {
stringstream s; s<<*i<<*i; m.insert(pair<int,string>(*i,s.str()));
}
for(multimap<int, string>::iterator i=m.begin();i!= m.end(); i++) {
cout<<*i<<" ";
}
return 0;
}
A. compilation error
B. program outputs: 3 4 2 1 0 1 2 3 4 0
C. program outputs: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4
D. program outputs: 00 11 22 33 44
E. program outputs: 0 0 1 1 2 2 3 3 4 4
正解:A
質問 6:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main() {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector<int> v1(t, t + 15);
set<int> s1(t, t + 15);
pair<set<int>::iterator, vector<int>::iterator > resultSet = equal(s1.begin(), s1.end(), v1.begin());
cout<<*resultSet.first<<" "<<*resultSet.second<<endl;
return 0;
}
Program outputs:
A. compilation error
B. 0 5
C. 4 2
D. 2 4
正解:A
小林** -
ソフト版とPDF版のCPP試験復習資料が勉強と、最終仕上げに役立ちました。見事で合格できました。
とても助かりました。ありがとうございました!