최신 CPP 무료덤프 - C++ Institute C++ Certified Professional Programmer
What happens when you attempt to compile and run the following code?
#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; }
};
int main() {
char s[]={"qwerty"};
char t1[]={"ert"};
char t2[]={"ERT"};
sort(s, s+6);
cout<<includes(s,s+6, t1,t1+3)<<" "<<includes(s,s+6, t2,t2+3)<<endl;
return 0;
}
Program outputs:
#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; }
};
int main() {
char s[]={"qwerty"};
char t1[]={"ert"};
char t2[]={"ERT"};
sort(s, s+6);
cout<<includes(s,s+6, t1,t1+3)<<" "<<includes(s,s+6, t2,t2+3)<<endl;
return 0;
}
Program outputs:
정답: A
What happens when you attempt to compile and run the following code?
# include <iostream>
# include <set>
# include <vector>
using namespace std;
int main(){
int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int>v(myints, myints+10);
set<int> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set<int>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<*i<<" ";
}
return 0;
}
# include <iostream>
# include <set>
# include <vector>
using namespace std;
int main(){
int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int>v(myints, myints+10);
set<int> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set<int>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<*i<<" ";
}
return 0;
}
정답: B
What happens when you attempt to compile and run the following code?
# include <deque>
# include <iostream>
# include <algorithm>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
deque<int> d1(t, t+10);
deque<int>::iterator it = lower_bound(d1.begin(), d1.end(), 4);
for_each(it, d1.end(), Out<int>(cout));cout<<endl;
return 0;
}
Program outputs:
# include <deque>
# include <iostream>
# include <algorithm>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
deque<int> d1(t, t+10);
deque<int>::iterator it = lower_bound(d1.begin(), d1.end(), 4);
for_each(it, d1.end(), Out<int>(cout));cout<<endl;
return 0;
}
Program outputs:
정답: D
Which changes introduced independently will allow code to compile and display 0 1 8 9
(choose all that apply)
#include <iostream>
# include <set>
# include <vector>
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(){
A t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<A>v(t, t+10);
set<A> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set<A>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<i?>getA()<<" ";
}
cout<<endl;
return 0;
}
(choose all that apply)
#include <iostream>
# include <set>
# include <vector>
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(){
A t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<A>v(t, t+10);
set<A> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set<A>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<i?>getA()<<" ";
}
cout<<endl;
return 0;
}
정답: A,C,D
What happens when you attempt to compile and run the following code?
# include <deque>
# include <iostream>
# include <algorithm>
using namespace std;
class B { int val;
public:
B(int v):val(v){}
int getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} }; ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} template<class T>struct Out {
ostream & out; Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};
deque<B> d1(t, t+10);
sort(d1.begin(), d1.end());
pair<deque<B> ::iterator, deque<B>::iterator > result = equal_range(d1.begin(), d1.end(),
B(20));
for_each(result.first, result.second, Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
# include <deque>
# include <iostream>
# include <algorithm>
using namespace std;
class B { int val;
public:
B(int v):val(v){}
int getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} }; ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} template<class T>struct Out {
ostream & out; Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};
deque<B> d1(t, t+10);
sort(d1.begin(), d1.end());
pair<deque<B> ::iterator, deque<B>::iterator > result = equal_range(d1.begin(), d1.end(),
B(20));
for_each(result.first, result.second, Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
정답: B
What happens when you attempt to compile and run the following code?
# include <vector>
# include <iostream>
# include <algorithm>
# include <functional>
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
operator int () const { return val;} };
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
struct Add : public binary_function<B, B, B> {
B operator() (const B & a, const B & b) const {
return a+b; } };
int main() {
B t[]={1,2,3,4,5,6,7,8,9,10};
vector<B> v1(t, t+10);
vector<B> v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), 1));
for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
# include <vector>
# include <iostream>
# include <algorithm>
# include <functional>
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
operator int () const { return val;} };
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
struct Add : public binary_function<B, B, B> {
B operator() (const B & a, const B & b) const {
return a+b; } };
int main() {
B t[]={1,2,3,4,5,6,7,8,9,10};
vector<B> v1(t, t+10);
vector<B> v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), 1));
for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
정답: C
What happens when you attempt to compile and run the following code?
# include <vector>
# include <iostream>
# include <algorithm>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator()(const T & val ) { out<<val<<" "; }
};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return start++; }
};
struct Odd { bool operator()(int v) { return v%2==0; } };
int main() {
vector<int> v1(10);
vector<int> v2(10);
generate(v1.begin(), v1.end(), Sequence(1));
stable_partition(v1.begin(),v1.end(), Odd());
for_each(v1.begin(), v1.end(), Out<int>(cout) );cout<<endl;
return 0;
}
Program outputs:
# include <vector>
# include <iostream>
# include <algorithm>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator()(const T & val ) { out<<val<<" "; }
};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return start++; }
};
struct Odd { bool operator()(int v) { return v%2==0; } };
int main() {
vector<int> v1(10);
vector<int> v2(10);
generate(v1.begin(), v1.end(), Sequence(1));
stable_partition(v1.begin(),v1.end(), Odd());
for_each(v1.begin(), v1.end(), Out<int>(cout) );cout<<endl;
return 0;
}
Program outputs:
정답: C
What happens when you attempt to compile and run the following code?
# include <vector>
# include <iostream>
# include <algorithm>
# include <functional>
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
B operator +(const B &b )const { return B(val + b.val);} };
ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
template<typename A> struct Add : public binary_function<A, A, A> {
A operator() (const A & a, const A & b) const { return a+b; }};
int main() {
int t[]={1,2,3,4,5,6,7,8,9,10};
vector<B> v1(t, t+10);
vector<B> v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add<B>()), 1)); for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
# include <vector>
# include <iostream>
# include <algorithm>
# include <functional>
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
B operator +(const B &b )const { return B(val + b.val);} };
ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
template<typename A> struct Add : public binary_function<A, A, A> {
A operator() (const A & a, const A & b) const { return a+b; }};
int main() {
int t[]={1,2,3,4,5,6,7,8,9,10};
vector<B> v1(t, t+10);
vector<B> v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add<B>()), 1)); for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
정답: E
What happens when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
string t[]={"aaa","Aaa", "aAa","aaA","bbb","Bbb", "bBb", "bbB"};
vector<string> v1(t, t+8);
sort(v1.begin(), v1.end());
for_each(v1.begin(), v1.end(), Out<string>(cout));cout<<endl;
return 0;
}
Program outputs:
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
string t[]={"aaa","Aaa", "aAa","aaA","bbb","Bbb", "bBb", "bbB"};
vector<string> v1(t, t+8);
sort(v1.begin(), v1.end());
for_each(v1.begin(), v1.end(), Out<string>(cout));cout<<endl;
return 0;
}
Program outputs:
정답: C
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template <typename T>
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T a) { _v+=a; }
template <class U>
U get(U a) {
return (U)(_v);
}
};
int main()
{
A<int> a(1);
a.add(10);
cout.setf( ios::showpoint);
cout << a.getV() << " " << a.get(1.0)<<endl;
return 0;
}
#include <iostream>
using namespace std;
template <typename T>
class A {
T_v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T a) { _v+=a; }
template <class U>
U get(U a) {
return (U)(_v);
}
};
int main()
{
A<int> a(1);
a.add(10);
cout.setf( ios::showpoint);
cout << a.getV() << " " << a.get(1.0)<<endl;
return 0;
}
정답: D
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };
vector<int> v1(t, t+10);
set<int> s1(t, t+10);
replace(v1.begin(), v1.end(), 1, 10);
replace(s1.begin(), s1.end(), 1, 10);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
int main() {
int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };
vector<int> v1(t, t+10);
set<int> s1(t, t+10);
replace(v1.begin(), v1.end(), 1, 10);
replace(s1.begin(), s1.end(), 1, 10);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
정답: B
What happens when you attempt to compile and run the following code?
# include <iostream>
# include <map>
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"}; map<int, string> m;
for (int i = 0; i < 10; i++) {
m.insert(pair<int, string>(t[i], s[i]));
}
if (m.count(3) == 2) {
m.erase(3);
}
for (map<int, string>::iterator i = m.begin(); i != m.end(); i++) {
cout << i?>first << " ";
}
return 0;
}
# include <iostream>
# include <map>
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"}; map<int, string> m;
for (int i = 0; i < 10; i++) {
m.insert(pair<int, string>(t[i], s[i]));
}
if (m.count(3) == 2) {
m.erase(3);
}
for (map<int, string>::iterator i = m.begin(); i != m.end(); i++) {
cout << i?>first << " ";
}
return 0;
}
정답: D
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, 6, 5, 7, 9, 8, 0 };
vector<int> v(t, t+10);
map<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(map<int, string>::iterator i=m.begin();i!= m.end(); i++) {
cout<<*i<<" ";
}
return 0;
}
# include <iostream>
# include <map>
# include <vector>
# include <sstream>
# include <string>
using namespace std;
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int> v(t, t+10);
map<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(map<int, string>::iterator i=m.begin();i!= m.end(); i++) {
cout<<*i<<" ";
}
return 0;
}
정답: E
Which lines of the code below contain proper instantiation of queue objects?
# include <iostream>
# include <deque>
# include <list>
# include <queue>
# include <vector>
using namespace std;
int main()
{
deque<int> mydeck;
list<int> mylist;
vector<int> myvector;
queue<int> first; // line I
queue<int> second(mydeck);// line II
queue<int> third(second);// line III
queue<int> fourth(mylist);// line IV
queue<int> fifth(myvector);// line V
return 0;
}
# include <iostream>
# include <deque>
# include <list>
# include <queue>
# include <vector>
using namespace std;
int main()
{
deque<int> mydeck;
list<int> mylist;
vector<int> myvector;
queue<int> first; // line I
queue<int> second(mydeck);// line II
queue<int> third(second);// line III
queue<int> fourth(mylist);// line IV
queue<int> fifth(myvector);// line V
return 0;
}
정답: A,C,D
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Compare {
bool operator ()(int a) {
if (a >5) return true;
return false;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector<int> v (t,t+15);
int number = count(v.begin(), v.end(), Compare());
cout<< number<<endl;
return 0;
}
Program outputs:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Compare {
bool operator ()(int a) {
if (a >5) return true;
return false;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector<int> v (t,t+15);
int number = count(v.begin(), v.end(), Compare());
cout<< number<<endl;
return 0;
}
Program outputs:
정답: E
What happens when you attempt to compile and run the following code?
# include <vector>
# include <iostream>
# include <algorithm>
using namespace std;
template<typename T>class B { T val;
public:
B(T v):val(v){}
T getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} }; template<class T>ostream & operator <<(ostream & out, const B<T> & v) { out<<v.getV(); return out;}
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
bool Less(const B<float> &a, const B<float> &b) { return int(a.getV())<int(b.getV());} int main() {
float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13};
vector<B<float> > v1; v1.assign(t, t+10);
stable_sort(v1.begin(), v1.end(), Less);
for_each(v1.begin(), v1.end(), Out<B<float> >(cout));cout<<endl;
return 0;
}
Program outputs:
# include <vector>
# include <iostream>
# include <algorithm>
using namespace std;
template<typename T>class B { T val;
public:
B(T v):val(v){}
T getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} }; template<class T>ostream & operator <<(ostream & out, const B<T> & v) { out<<v.getV(); return out;}
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
bool Less(const B<float> &a, const B<float> &b) { return int(a.getV())<int(b.getV());} int main() {
float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13};
vector<B<float> > v1; v1.assign(t, t+10);
stable_sort(v1.begin(), v1.end(), Less);
for_each(v1.begin(), v1.end(), Out<B<float> >(cout));cout<<endl;
return 0;
}
Program outputs:
정답: C
What happens when you attempt to compile and run the following code?
# include <deque>
# include <iostream>
# include <algorithm>
# include <functional>
using namespace std;
class B { int val;
public:
B(int v):val(v){}
int getV() const {return val;} bool operator > (const B & v) const { return val>v.val;} }; ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} template<class T>struct Out {
ostream & out; Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};
deque<B> d1(t, t+10);
sort(d1.begin(), d1.end(), greater<B>());
pair<deque<B> ::iterator, deque<B>::iterator > result = equal_range(d1.begin(), d1.end(),
B(20), greater<B>());
for_each(result.first, result.second, Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
# include <deque>
# include <iostream>
# include <algorithm>
# include <functional>
using namespace std;
class B { int val;
public:
B(int v):val(v){}
int getV() const {return val;} bool operator > (const B & v) const { return val>v.val;} }; ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;} template<class T>struct Out {
ostream & out; Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int main() {
int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};
deque<B> d1(t, t+10);
sort(d1.begin(), d1.end(), greater<B>());
pair<deque<B> ::iterator, deque<B>::iterator > result = equal_range(d1.begin(), d1.end(),
B(20), greater<B>());
for_each(result.first, result.second, Out<B>(cout));cout<<endl;
return 0;
}
Program outputs:
정답: C
What happens when you attempt to compile and run the following code? Choose all that apply.
# include <iostream>
# include <fstream>
# include <string>
# include <list>
# include <algorithm>
#include <iomanip>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) {out<<setw(3)<<hex<<val; } };
int main () {
int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fstream f("test.out", ios::trunc|ios::out);
list<int> l(t, t+10);
for_each(l.begin(), l.end(), Out<int>(f));
f.close(); f.open("test.out");
for( ; f.good() ; ) {
int i; f>>i;
cout<<i<<" ";
}
f.close();
return 0;
}
# include <iostream>
# include <fstream>
# include <string>
# include <list>
# include <algorithm>
#include <iomanip>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) {out<<setw(3)<<hex<<val; } };
int main () {
int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
fstream f("test.out", ios::trunc|ios::out);
list<int> l(t, t+10);
for_each(l.begin(), l.end(), Out<int>(f));
f.close(); f.open("test.out");
for( ; f.good() ; ) {
int i; f>>i;
cout<<i<<" ";
}
f.close();
return 0;
}
정답: B,C,D,E