Advanced C++ - Final Test - InfraExam 2024
Advanced C++ - Final Test - InfraExam 2024
Search...
(https://infraexam.com/)
MENU (HTTPS://INFRAEXAM.COM/#MOBILE-MENU-TOGGLE)
AD
AD
CCNA1 v7
CCNA2 v7
CCNA3 v7
1. What happen if you try to compile and run this program?
Modules 16 – 17 Exam
Answers
#include<iostream> (https://infraexam.com/c
#include<string> v7/ccna1-v7-itnv7-modul
#include<vector> 16-17-building-and-secur
#include<algorithm> a-small-network-exam-
#include<iomanip> answers/)
#include<fstream>
Practice Final – ITN Ans
using namespace std;
(https://infraexam.com/c
void
v7/ccna1-v7-itnv7-practi
printer (int i)
final-itn-answers/)
{
cout <<setw(2) << i <<", "; Course Feedback
} (https://infraexam.com/c
v7/ccna-1-itn-version-7-0
int course-feedback-7-02-
answers/)
main()
{ ITN Practice PT Skills
int mynumbers[] = {8, 9, 7, 6, 4, 1}; Assessment (PTSA)
vector<int> v1 (mynumbers, mynumbers + 6); (https://infraexam.com/c
fstream outfile("output.txt", ios::trunc | ios:: v7/itn-version-7-00-itn-
int i = 0; practice-pt-skills-assessm
while(i > 1); //LINE I ptsa/)
{
Final Exam Answers
outfile >> i; //LINE II
(https://infraexam.com/c
i = v1[0];
v7/ccna1-v7-itnv7-final-e
v1.pop_back();
answers/)
}
outfile.close();
for_each(v1.begin(), v1.end(), printer);
Categories
outfile.close();
outfile.open("output.txt"); NEW
CCNA1 v7 – ITN – Lab Answers
return 0; (https://infraexam.com/category/c
} cna1-v7-itn-lab-answers/)
runtime error at LINE I CCNA1 v7 – ITN – Packet Tracer
the program outputs 4, 6, 7, 8, 9, Answers
compilation error in LINE II (https://infraexam.com/category/c
if there are element in the container. Choose all that apply: cna2-v7-srwe-lab-answers/)
CyberOps Associate– CA –
Packet Tracer Answers
(https://infraexam.com/category/c
yberops-associate-ca-packet-
tracer-answers/)
Re-Appear
(https://infraexam.com/category/r
e-appear/)
SEO
(https://infraexam.com/category/s
eo/)
SEO-Lab
(https://infraexam.com/category/s
eo-lab/)
Uncategorized
(https://infraexam.com/category/u
ncategorized/)
NEW
Updated
(https://infraexam.com/category/u
pdated/)
following code? AD
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value): value(value){}
int getValue()const
{
return value;
}
bool operator < (const Pocket & _Right) const
{
return value < _Right.value;
}
};
bool
operator == (Pocket & _Left, int _Right)
{
return(_Left.getValue() == _Right);
}
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream;
}
void
printer (Pocket i) NEW
{
cout << i << ", ";
}
int
main()
{
int mynumbers[] = {8, 9, 7, 6, 4, 1};
vector<Pocket> v1 (mynumbers, mynumbers + 6);
sort (v1.begin(), v1.end()); //LINE I
remove(v1.begin(), v1.end(), 2); //LINE II
for_each(v1.begin(), v1.end(), printer);
return 0;
}
NEW
4. What happen if you try to compile and run this program?
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
void
printer(int i)
{
cout << i << ", ";
}
int
main()
{
int mynumbers1[] = {8, 9, 7, 6, 4, 1};
int mynumbers2[] = {7, 8, 7, 4, 5, 1};
vector<int> v1 (mynumbers1, mynumbers1 + 6);
vector<int> v2 (mynumbers1, mynumbers1 + 6);
vector<int> v3 (mynumbers2, mynumbers2 + 6); //L
transform(v1.begin(), v1.end(), v2.rbegin(), v3.
for_each(v3.rbegin(), v3.rend(), printer);
return 0;
}
AD
NEW
5. What will happen when you attempt to compile and run the
NEW
following code?
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value): value(value){}
int getValue()const
{
return value;
}
bool operator < (const Pocket & _Right) const
{
return value < _Right.value;
}
};
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream;
}
void
printer (Pocket i)
{
cout << i << ", ";
}
int
main() NEW
{
int mynumbers1[] = {8, 9, 7, 6 };
int mynumbers2[] = {4, 1, 4, 5 };
vector<Pocket> v1(7, 0);
sort (mynumbers2, mynumbers2 + 4);
copy (mynumbers1, mynumbers1 + 3, v1.begin ());
copy (mynumbers2, mynumbers2 + 3, v1.begin () +
sort (mynumbers1, mynumbers1 + 4); //LINE I
inplace_merge (v1.begin (), v1.begin() + 4, v1.
for_each(v1.begin(), v1.end(), printer);
return 0;
}
vector ;;;;
6.
NEW
What will happen when you attempt to compile and run the
NEW
following code?
#include<vector>
#include<iostream>
#include<set>
#include<deque>
#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++ % 7;
}
};
int
main()
{
vector < int > v1(3);
generate (v1.begin (),v1.end (), Sequence (10));
set < int >s1(v1.rbegin (), v1.rend ()); NEW
7.
#include<iomanip>
#include<iostream>
using namespace std;
int
main()
{
double goodpi = 3.141593;
double badpi = 3.5;
cout << goodpi << ", ";
cout << setprecision (3); //LINE I
cout << goodpi << ", "; //LINE II
cout << badpi<< ", ";
return 0;
}
NEW
8.
#include<iostream>
using namespace std;
template < class T > void
f (T & a) //LINE I
{
cout << 1 + a << end1;
}
int
main()
{
double a = 1.5;
f < float & > (a); //LINE II
return 0;
}
NEW
9. What happen if you try to compile and run this program?
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int
main()
{
int mynumbers[] = { 8, 9, 7, 6, 4, 1 };
vector < int >v (mynumbers, mynumbers + 6);
set < int >s1 (v.begin (), v.end());
s1.erase (s1.lower_bound (4), s1.upper_bound (9)
s1.insert (10); //LINE II
s1.insert (v.begin (), v.end());
for (set < int >::iterator i = s1.begin (); i !=
cout << *i <<", ";
return 0;
}
10.
NEW
What happen if you try to compile and run this program?
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
void
printer (int i)
{
cout << i << ", ";
}
int
main()
{
int mynumbers1[] = { 8, 9, 7, 6 };
int mynumbers2[] = { 4, 1, 4, 5 };
vector < int >v1 (3);
sort (mynumbers2, mynumbers2 + 3);
sort (mynumbers1, mynumbers1 + 3); //LINE I
set_symmetric_difference (mynumbers1, mynumbers1
mynumbers2 + 2, v1.begin ()); //LINE II
for_each (v1.begin (), v1.end(), printer);
return 0;
}
program outputs 1, 4, 4,
runtime error at LINE II
program outputs 1, 4, 7, 0, 0,
compilation error in LINE I NEW
runtime error at LINE I
11. What happen if you try to compile and run this program?
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
struct Add:public binary_function < int, int, int
{
int operator () (const int &_Left, const int &_R
{
return _Left + _Right;
}
};
void
printer (int i)
{
cout << i << ", ";
}
int
main()
{
int mynumbers[] = { 8, 9, 7, 6, 4, 1 };
vector < int >v1 (mynumbers, mynumbers + 6);
vector < int > v2 (7);
transform (v1.begin (), v1.end (), v2.begin (),
for_each (v2.rbegin (), v2.rend(), printer);
return 0;
}
NEW
12.
NEW
Which of the following is are legal variable names?
#include<vector>
#include<iostream>
#include<string>
using namespace std;
template < typename T > ostream & print (const T &
{
T tmp = start;
for (; tmp != end; ++tmp)
{
cout << *tmp << " "; //LINE I
}
return cout;
}
class A
{
public:
int a;
public:
A (int a):a (a) {}
};
ostream & operator<< (ostream & c, const A & o)
{
c << o.a;
return c;
}
int
main()
{
int tab[] = { 1, 5, 3, 3, 5, 6 };
vector < A >v1 (tab, tab + 6); //LINE II NEW
program outputs: 1, 5, 3, 3, 5, 6, 1
program outputs: 1, 5, 3, 3, 5, 6,
NEW
13. What happen if you try to compile and run this program?
#include<iostream>
#include<map>
#include<vector>
#include<sstream>
#include<string>
using namespace std;
int
main()
{
int mynumbers[] = { 3, 9, 3, 2, 1, 4, 5 };
vector < int >v (mynumbers, mynumbers + 7);
map < int, string > m;
for (vector < int >::iterator i = v.begin(); i !
{
stringstream s;
s << *i;
m.insert(pair<int, string>(*i, s.str()));
}
pair<map<int, string>:: iterator, map<int, strin
range = m.equal_range(3);
map<int, string>::iterator i = range.first; //LI
for(; i != range.second; i++)
{
cout << i->second <<", "<<i->first<<", ";
}
return 0;
}
program outputs: 3, 3, 9, 9, 3, 3,
program outputs: 3, 3,
compilation error in LINE I
program outputs: 0, 0, 3, 3,
AD
14.
NEW
What happen if you try to compile and run this program?
#include<iostream>
using namespace std;
class SomethingSpecial
{
public:
double value;
program outputs: 6, 6,
compilation error in LINE II
program outputs: 3, 3,
AD
15.
NEW
What happen if you try to compile and run this program?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void
printer(int i)
{
cout << i <<", ";
}
int
main()
{
int mynumbers[] = {8, 9, 7, 6, 4, 1};
vector<int>v1 (mynumbers, mynumbers + 6);
for_each(v1.begin(), v1.end(), bind2nd(plus<int>
for_each(v1.rbegin(), v1.rend(),printer); //LINE
return 0;
}
NEW
16. What happen if you try to compile and run this program?
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value):value(value){}
int getValue()const
{
return value;
}
bool operator <(const Pocket & _Right)const
{
return value<_Right.value;
}
bool operator <(const int & _Right) const
{
return value < _Right;
}
operator int () const
{
return value;
}
};
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream; NEW
}
void
printer(Pocket i)
{
cout << i <<", ";
}
int
main()
{
Pocket mynumbers1[] = {4, 9, 1, 6};
int mynumbers2[] = {4, 1, 4, 5};
vector<Pocket>v1 (7, 0);
sort (mynumbers2, mynumbers2 + 4);
sort (mynumbers1, mynumbers1 + 4); //LINE I
set_intersection(mynumbers1, mynumbers1 +3, mynu
for_each(v1.begin(), v1.end(),printer);
return 0;
}
17.
NEW
What happen if you try to compile and run this program?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value):value(value){}
int getValue()const
{
return value;
}
operator int ()const
{
return value;
}
bool operator <(const Pocket & _Right) const
{
return value < _Right.value;
}
};
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream;
}
void
printer(Pocket i) NEW
{ //LINE I
cout << i <<", ";
}
struct Add:public binary_function<Pocket, Pocket,
{
Pocket operator() (const Pocket & _Left, const P
{
return _Left + _Right;
}
};
int
main()
{
Pocket mynumbers1[] = {8, 9, 7, 6, 4, 1};
vector<Pocket>v1 (mynumbers1, mynumbers1 + 6);
vector<Pocket> v2(6,0);
transform(v1.begin(),v1.end(), v2.begin(),bind2n
for_each(v2.rbegin(), v2.rend(),printer);
return 0;
}
NEW
18. What happen if you try to compile and run this program?
#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value):value(value){}
int getValue()const
{
return value;
}
bool operator < (const Pocket & _Right)const
{
return value < _Right.value;
}
};
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream;
}
int
main()
{
Pocket mynumbers1[] = {8, 9, 7, 6, 4, 1};
Pocket mynumbers2[] = {Pocket(3), Pocket(2),Pock
deque<Pocket> d1(mynumbers1, mynumbers1 + 6); NEW
NEW
19. What happen if you try to compile and run this program?
#include <deque>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void
printer(int i)
{
cout << i <<", ";
}
struct multiAdd:public binary_function<int, int, i
{
int operator()(const int & _Left, const int & _R
{
return 2 *(_Left + _Right);
}
};
int
main()
{
int mynumbers[] = {8, 9, 7, 6, 4, 1};
deque<int> d1(mynumbers, mynumbers + 6);
deque<int>d2(6); //LINE I
transform (d1.begin(), d1.end(), d2.begin(), bin
for_each(d2.begin(), d2.end(), printer);
return 0;
}
NEW
20. What happen if you try to compile and run this program?
#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value):value(value){}
int getValue()const
{
return value;
}
bool operator <(const Pocket & _Right) const
{
return value < _Right.value;
}
};
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream;
}
void
printer(Pocket i)
{
cout << i <<", ";
}
int
main() NEW
{
int mynumbers[] = {8, 9, 7, 6, 4, 1};
deque<Pocket> d1(mynumbers, mynumbers +6);
d1.push_back(4); //LINE I
deque<Pocket> ::iterator it = lower_bound(d1.beg
for_each(it, d1.end(), printer);
return 0;
}
NEW
21. What happen if you try to compile and run this program?
#include <deque>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value):value(value){}
int getValue()const
{
return value;
}
bool operator > (const Pocket & _Right) const
{
return value > _Right.value;
}
};
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream;
}
void
printer(Pocket i)
{
cout << i <<", ";
}
int NEW
main()
{
int mynumbers[] = {8, 9, 7, 6, 4, 1};
deque<Pocket> d1(mynumbers, mynumbers +6);
sort (d1.begin(), d1.end(), greater<Pocket>());
deque<Pocket> ::iterator it = lower_bound(d1.beg
for_each(it, d1.end(), printer);
return 0;
}
NEW
22. What happen when you attempt to compile and run the
NEW
following code?
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<typename T> class Pocket
{
T value;
public:
Pocket(T value):value(value){}
T getValue()const
{
return value;
}
bool operator<(const Pocket & _Right)const
{
return value <_Right.value;
}
};
template<typename T>
ostream & operator<<(ostream & stream, const Poc
{
stream << pocket.getValue();
return stream;
}
void
printer(Pocket<double> i)
{
cout << i <<", ";
}
bool NEW
1.15,
the program outputs 1.11, 2.12, 3.13, 5.15, 6.16,
1.15,
runtime error at LINE II
compilation error in LINE II
the program outputs 1.11, 1.15, 2.12, 3.13, 5.15,
6.16,
compilation error in LINE I
runtime error at LINE II
NEW
23. What happen when you attempt to compile and run the
following code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;
int
main()
{
int mynumbers[] = {8, 9, 7, 6, 4, 1};
vector<int>v1 (mynumbers, mynumbers + 6);
deque<int>d1 (mynumbers, mynumbers + 6);
set<int>s1 (mynumbers, mynumbers + 6);
vector<int>::iterator found = find(v1.begin(), v
if(found != v1.end())
cout << "found"<<", ";
cout << find (d1.begin(), d1.end(),9)<<", "; //L
cout << find (s1.begin(), s1.end(), 6); //LINE I
return 0;
}
8, 9,
program output: 9, 6,
compilation error in LINE II
program output: 8, 9, 7, 6, 4, 1, 1, 4, 6, 7, 8, 9,
NEW
24. What happens if you try to compile and run this program?
#include <iostream>
using namespace std;
int
main()
{
cout <<31.23<<", ";
cout.setf(ios::hex, ios::basefield);
cout.setf(ios::showbase); //LINE I
cout << 31.23 <<", ";
cout.unsetf (ios::showbase); //LINE II
cout <<63.23 <<", ";
return 0;
}
NEW
25. What happens if you try to compile and run this program?
#include <iostream>
using namespace std;
template<typedef T> //LINE I
class Pocket
{
public:
T value;
Pocket(T value)
{
}; //LINE II
};
int
main()
{
Pocket<double> a(7);
cout << a.value<<endl;
return 0;
}
NEW
26. What happens if you try to compile and run this program?
#include <iostream>
#include <string>
using namespace std;
template<class Ty> class Pocket
{
Ty value;
public:
Pocket(){}
Pocket (Ty value);
Ty getValue()
{
return value;
}
void add (Ty _Right)
{
value += _Right;
}
template<class Tx> Tx get(Tx _Right)
{
return (Tx) (value) + _Right; //LINE I
}
friend ostream & operator << (ostream & _os, con
{
_os <<value.value;
return _os;
}
};
template<class T> Pocket<T> ::Pocket (T value):val
int
main() NEW
{
Pocket<int> a(3);
cout << a <<", ";
cout <<a.get <double> (2);
return 0;
}
program output: 3, 5
program output: 3, 3
program output: 3, 6
compilation error in LINE II
compilation error in LINE I
27. What happens if you try to compile and run this program?
#include <iostream>
using namespace std;
int
main()
{
cout <<31<<", ";
cout.setf(ios::hex); //LINE I
cout << 31 <<", ";
cout.setf(ios::showbase, ios::basefield); //LINE
cout <<63 <<", ";
return 0;
}
28. What will happens when attempt to compile and run the
following code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int
main()
{
int mynumbers[] = {8, 9, 7, 6, 1, 1, 6, 6};
vector <int> v(mynumbers, mynumbers + 8);
vector<int>::iterator it = search_n(v.begin(), v
cout << it - v.begin() <<", "; //LINE II
return 0;
}
NEW
29. What happens if you try to compile and run this program?
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value):value(value){}
int getValue()const
{
return value;
}
bool operator <(const Pocket & _Right) const
{
return value <_Right.value;
}
bool operator <(const int & _Right)const
{
return value <_Right;
}
operator int () const
{
return value;
}
};
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream; NEW
}
void
printer (Pocket i)
{
cout << i <<", ";
}
int
main()
{
Pocket mynumbers1[] = {8, 9, 7, 6};
int mynumbers2[] = {4, 1, 4, 5};
vector<Pocket> v1(7, 0);
sort(mynumbers2, mynumbers2 + 4);
sort(mynumbers1, mynumbers1 + 4); //LINE I
set_symmetric_difference(mynumbers1, mynumbers1
for_each(v1.begin(), v1.end(), printer);
return 0;
}
NEW
30. What happens when you attempt to compile and run the
following code ?
#include <iostream>
#include <map>
#include <string>
using namespace std;
int
main()
{
int mynumbers[] = {8, 9, 7, 6, 4, 1};
string words[] = {"eight", "nine", "seven", "six
map<int, string>m;
for(int i=0; i<6;i++)
m.insert(pair<int, string>(mynumbers[i], words
if(m[2].value =="seven") //LINE II
cout<<"seventh element, ";
for(map <int, string>::iterator i = m.begin(); i
cout<< i->second << ", ";
cout<<m.size(); //LINE III
return 0;
}
nine,
program outputs: seven element, one, , four, six,
nine, 7
NEW
runtime error at LINE II
compilation error in LINE II
31. What happens if you try to compile and run this program ?
#include <iostream>
using namespace std;
void
f(double a) //LINE II
{
cout << 2 + a <<endl;
}
template <class A>void
f(A & a) //LINE I
{
cout << 1 + a << endl;
}
int
main()
{
double a = 1.5;
f(a); //LINE III
return 0;
}
NEW
32. What will happens when you attempt to compile and run the
following code ?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int
main()
{
int mynumbers[] = {8, 9, 7, 6, 4, 1};
vector <int>v (mynumbers, mynumbers + 6);
vector <int>::iterator it;
int m1[] = { 7, 6, 4 };
it = find_end (v.begin (), v.end(), m1,m1 + 3);
if (it != v.end ())
cout<<"Found at position: " << it - v.begin () <
return 0;
}
NEW
33. Which sentences are 100% true about the code
below(multiple choice)when control reaches return:
#include <vector>
#include <iostream>
using namespace std;
int
main()
{
vector <int>v1 (10, -1);
vector <int>v2;
v2.reserve (10);
for(unsigned i = 0; i<10; i++)
{
v2.push_back(i);
}
cout<< v2[0] << ", " << v1[0];
return 0;
}
program outputs: 0, -1
program outputs: 0, 0
NEW
34. What will happens when you attempt to compile and run the
following code ?
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void
printer (int i)
{
cout << i <<", ";
}
int
main()
{
int mynumbers1[] = {8, 9, 7, 6 };
int mynumbers2[] = {4, 1, 4, 5 };
vector <double>v1 (7);
sort (mynumbers2, mynumbers2 + 4);
sort (mynumbers1, mynumbers1 + 4); //LINE I
int m1[] = { 7, 6, 4 };
merge (mynumbers1, mynumbers1 + 2, mynumbers2, m
for_each (v1.begin (), v1.end (), printer);
return 0;
}
program outputs 1, 4, 6, 7, 0, 0,
compilation error in LINE II
compilation error in LINE I
program outputs 1, 4, 4, 6,
program outputs 1, 4, 6, 7, 0, 0, 0,
NEW
runtime error at LINE I
35. What will happens when you attempt to compile and run the
following code assuming that you will enter following
sequence: i j k jk q<enter> ?
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void
printer (string i)
{
cout<<i<<", ";
}
int
main()
{
vector <string>v1;
string s;
do
{
cin >> s;
v1.push_back(s); //LINE I
}
while (s != "q" && cin.good()); // LINE II
for_each (v1.begin (), v1.end(), printer);
return 0;
}
#include <iostream>
using namespace std;
template < class T > void
f (T & a) //LINE I
{
cout << 2 * a <<endl;
}
int
main()
{
int a = 2;
f(a); //LINE III
return 0;
}
queue q;
list 1; queue q(1);
array_list 1; queue q(1);
deque d; queue q(d);
vector v; queue q(v);
NEW
38. What happens when you attempt to compile and run the
code?
#include <iostream>
#include <map>
using namespace std;
int
main()
{
int mynumbers[] = { 8, 9, 7, 6, 4, 1, 4 };
string words[] = { "eight", "nine", "seven", "si
map < int, string > m;
for (int i = 0; i < 7; i++)
{
m.insert (pair < int, string > (mynumbers[i
}
if (m.count (4) == 2)
m.erase(2); //LINE II
for(map <int, string>::iterator i = m.begin(); i
{
cout << i->first << ", ";
}
return 0;
}
program outputs: 1, 6, 7, 8, 9, 4
program outputs: 1, 4, 6, 7, 8, 9, 4,
compilation error in LINE II
program outputs: 1, 4, 7, 8, 8, 9, 4,
compilation error in LINE I
program outputs: 1, 4, 6, 7, 8, 9,
NEW
runtime error at LINE II
39. What happens if you try to compile and run this program?
#include <iostream>
using namespace std;
int
main()
{
cout << 31 << ", ";
cout.setf (ios::hex, ios::basefield);
cout.setf (ios::showbase); //LINE I
cout << 31 << ", ";
cout.unsetf (ios::showbase); //LINE II
cout << 63 << ", ";
return 0;
}
NEW
40. What will happens when you attempt to compile and run the
following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int Mul (int & _Left)
{
if(_Left <= 3)
return 2 * _Left;
else
return 6;
}
int
main()
{
int mynumbers[] = { 8, 9, 7, 6, 4, 1, 4 };
vector < int > v1 (mynumbers, mynumbers + 7);
vector < int >v2 (7);
transform (v1.begin (), v1.end(), v2.begin (), p
vector < int >::iterator it = find_if (v2.begin
cout << *it <<endl; //LINE III
return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;
void
myprint (int i)
{
cout << i << ", ";
}
int
main()
{
int mynumbers[] = { 8, 9, 7, 6, 4, 1 };
vector < int > v1 (mynumbers, mynumbers + 6);
v1.pop_back ();
v1.pop_back ();
v1.pop_back ();
set < int > s1 (mynumbers, mynumbers + 6);
deque < int > d1 (mynumbers, mynumbers + 6);
v1.pop_front (); //LINE I
v1.pop_front ();
v1.pop_front ();
for_each (v1.begin (), v1.end (), myprint); //L
for_each (s1.begin (), s1.end (), myprint);
for_each (d1.begin (), d1.end (), myprint);
return 0;
} NEW
program outputs: 8, 9, 7, 6, 4, 1, 4, 6, 7, 8, 9, 6,
4, 1,
NEW
42. What happens if you try to compile and run this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class A
{
int a;
public:
A (int a):a (a)
{
}
int getA () const
{
return a;
}
void setA (int a)
{
this->a = a;
}
bool operator == (const A & b) const
{
return a == b.a;
}
};
int
main()
{
cout << 31 << ", ";
cout.setf (ios::hex, ios::basefield);
cout.setf (ios::showbase); //LINE I NEW
NEW
43. What happens if you try to compile and run this program?
#include <vector>
#include <iostream>
#include <functional>
#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++ % 7;
}
};
int
main()
{
vector<int>v1(5);
generate(v1.rbegin(),v1.rend(),Sequence(8)); //L
rotate(v1.begin(), v1.begin() + 1, v1.end()); // NEW
for_each(v1.begin(), v1.end(),Out<int>(cout));
return 0;
}
#include <iostream>
using namespace std;
int
main()
{
cout<<31<<", ";
cout.setf(ios::oct, ios::basefield);
cout.setf(ios::showbase); //LINE I
cout<<31<<", ";
cout.unsetf(ios::showbase); //LINE II
cout<<63<<", ";
return 0;
}
45. What will happen when you attempt to compile and run the
following code assuming that you will enter following
sequence: 4 5 6 <enter> ?
#include <iostream>
#include <string>
using namespace std;
int
main()
{
string s;
getline(s); //LINE I
cout << s <<", "<< s <<", "<<endl; //LINE II
return 0;
}
NEW
46. What will happen when you attempt to compile and run the
following code?
#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
void
printer (int i)
{
cout << i <<", ";
}
int
main()
{
int mynumbers[]={8, 9, 7, 6, 4, 1};
deque<int>d1(mynumbers, mynumbers + 6);
deque<int>::iterator it = lower_bound(d1.begin()
d1.push_back(4); //LINE I
for_each(it, d1.end(), printer); //LINE II
return 0;
}
NEW
47. What will happen when you attempt to compile and run the
following code?
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
int
main()
{
int t[]={1, 5, 1, 4, 2};
vector<int>v (t, t + 5);
priority_queue<int> q(v.begin(),v.end()); //LINE
q.push(4); //LINE II
cout << q.top() <<", ";
q.push(3);
cout << q.top() << endl;
return 0;
}
program outputs: 4, 4
runtime error at LINE II
compilation error in LINE II
program outputs: 5, 5
compilation error in LINE I
program outputs: 4, 3
NEW
48. What happens if you try to compile and run this program?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket
{
int value;
public:
Pocket(int value): value(value){}
int getValue() const
{
return value;
}
operator int ()const
{
return value;
}
bool operator<(const Pocket & _Right)const
{
return value < _Right.value;
}
};
ostream & operator << (ostream & stream, const Poc
{
stream << pocket.getValue();
return stream;
}
void
printer (Pocket i) NEW
{ //LINE I
cout << i <<", ";
}
int
main()
{
Pocket mynumbers1[] = {8, 9, 7, 6, 4, 1};
Pocket mynumbers2[] = {8, 9, 1, 2, 2, 1};
vector<Pocket>v1(mynumbers1, mynumbers1 + 6);
vector<Pocket> v2(mynumbers2, mynumbers2 + 6);
vector <Pocket> v3(6, 0);
transform(v1.begin(), v1.end(), v2.begin(), v3.b
for_each(v1.rbegin(), v1.rend(), printer);
return 0;
}
NEW
49. What happen if you try to compile and run this program?
#include <iostream>
using namespace std;
template <class T> class Pocket
{
public:
T value;
Pocket(T value);
};
template <class T> Pocket<T>::Pocket(T value):valu
{
} //LINE I
int
main()
{
Pocket<double> a(7); //LINE II
cout << a.value <<endl;
return 0;
}
NEW
50. What will happen when you attempt to compile and run the
following code assuming that you will enter following
sequence: false true true<enter> ?
#include <iostream>
using namespace std;
int
main()
{
bool c1, c2, c3;
cin >> boolalpha >> c1 >> c2 >> c3;
cout << boolalpha << c3 <<", "<< c1 <<", " << c2
return 0;
}
M1 M4 M7
(https://infraexam.com/c- (https://infraexam.com/c- (https://infraexam
institute/cpp-advanced- institute/cpp-advanced- institute/cpp-adv
programming-in-c/stl- programming-in- programming-in-
sequential-containers- c/modifying-stl- c/utilities-and- NEW
m1-test/) algorithms-m4-test/) functional-tools-
m7-test/)
M2 M5 M8
(https://infraexam.com/c- (https://infraexam.com/c- (https://infraexam
institute/cpp-advanced- institute/cpp-advanced- institute/cpp-adv
programming-in- programming-in- programming-in-
c/associative-stl- c/sorting-stl-algorithms- c/advanced-inpu
containers-m2-test/) m5-test/) output-operation
test/)
M3 M6 M9
(https://infraexam.com/c- (https://infraexam.com/c- (https://infraexam
institute/cpp-advanced- institute/cpp-advanced- institute/cpp-adv
programming-in-c/non- programming-in- programming-in-
modifying-stl- c/merging-stl- c/templates-m9-t
operations-m3-test/) algorithms-m6-test/)
NEW