0% found this document useful (0 votes)
2K views74 pages

Advanced C++ - Final Test - InfraExam 2024

Uploaded by

Eralyn etsecal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views74 pages

Advanced C++ - Final Test - InfraExam 2024

Uploaded by

Eralyn etsecal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

InfraExam 2024

Search... 
(https://infraexam.com/)

 MENU (HTTPS://INFRAEXAM.COM/#MOBILE-MENU-TOGGLE)

AD

Advanced C++ | Final Test


Home (https://infraexam.com/) » C++ Institute (https://infraexam.com/c-institute/) » CPP – Advanced Programming in C++ (h

AD

CCNA1 v7

CCNA2 v7

CCNA3 v7

System Test Exam Answe


(https://infraexam.com/c
NEW

Advanced C++ | Final Test v7/ccna-1-itn-v7-02-syste


test-course-version-1-1-
system-test-exam-answer

 CPP : All Parts Modules 1 – 3 Exam Ans
(https://infraexam.com/c
v7/ccna1-v7-itnv7-modul
CPP – Advanced Programming in C++ : All Parts
3-basic-network-connect
(https://infraexam.com/c-institute/cpp-advanced-programming-in
and-communications-exa
M1 M4 M7 answers/)
(https://infraexam.com/c- (https://infraexam.com/c- (https://infraexam
Modules 4 – 7 Exam Ans
institute/cpp-advanced- institute/cpp-advanced- institute/cpp-adv
(https://infraexam.com/c
programming-in-c/stl- programming-in- programming-in-
v7/ccna1-v7-itnv7-modul
sequential-containers- c/modifying-stl- c/utilities-and-
7-ethernet-concepts-exam
m1-test/) algorithms-m4-test/) functional-tools-
answers/)
m7-test/)
Modules 8 – 10 Exam
M2 M5 M8
Answers
(https://infraexam.com/c- (https://infraexam.com/c- (https://infraexam
(https://infraexam.com/c
institute/cpp-advanced- institute/cpp-advanced- institute/cpp-adv
v7/ccna1-v7-itnv7-modul
programming-in- programming-in- programming-in-
10-communicating-betwe
c/associative-stl- c/sorting-stl-algorithms- c/advanced-inpu
networks-exam-answers/
containers-m2-test/) m5-test/) output-operation
Modules 11 – 13 Exam
test/)
Answers
M3 M6 M9
(https://infraexam.com/c
(https://infraexam.com/c- (https://infraexam.com/c- (https://infraexam
v7/ccna1-v7-itnv7-modul
institute/cpp-advanced- institute/cpp-advanced- institute/cpp-adv
11-13-ip-addressing-exam
programming-in-c/non- programming-in- programming-in-
answers/)
modifying-stl- c/merging-stl- c/templates-m9-t
Modules 14 – 15 Exam
operations-m3-test/) algorithms-m6-test/)
Answers
Summary Test (https://infraexam.com/c-institute/cpp-advanced-progr
(https://infraexam.com/c
in-c/advanced-c-summary-test/)
v7/ccna1-v7-itnv7-modul
Final Test (https://infraexam.com/c-institute/cpp-advanced-programm 14-15-network-applicatio
c/advanced-c-final-test/) communications-exam-
answers/)
NEW


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

program run forever without output cna1-v7-itn-packet-tracer-


answers/)
the program outputs 8, 9, 7, 6, 4, 1,
compilation error in LINE I CCNA2 v7 – SRWE – Lab
the program outputs 8, 9, 7, 6, 4, Answers

2. Which methods from std::deque class can be used to check (https://infraexam.com/category/c

if there are element in the container. Choose all that apply: cna2-v7-srwe-lab-answers/)

CCNA2 v7 – SRWE – Packet


clear()
Tracer Answers
isfull() (https://infraexam.com/category/c
empty() cna2-v7-srwe-packet-tracer-

there is no such method answers/)

isempty() CCNA3 v7 – ENSA – Lab


size() Answers
(https://infraexam.com/category/c
cna3-v7-ensa-lab-answers/)

CCNA3 v7 – ENSA – Packet


Tracer Answers
(https://infraexam.com/category/c
cna3-v7-ensa-packet-tracer-
answers/)

CyberOps Associate– CA – Lab


Answers
(https://infraexam.com/category/c
yberops-associate-ca-lab-
answers/)

CyberOps Associate– CA –
Packet Tracer Answers
(https://infraexam.com/category/c
yberops-associate-ca-packet-
tracer-answers/)

DevNet – DEVASC – Lab


Answers NEW
(https://infraexam.com/category/d
evnet-devasc-lab-answers/)

DevNet – DEVASC – Packet 


Tracer Lab Answers
3. What will happen when you attempt to compile and run the (https://infraexam.com/category/d
evnet-devasc-packet-tracer-lab-
answers/)

ITEv7 – Lab Answers


(https://infraexam.com/category/it
ev7-lab-answers/)

NE 2.0 – Lab Answers


(https://infraexam.com/category/n
e-2-0-lab-answers/)

NE 2.0 Packet Tracer Activity Lab


Answers
(https://infraexam.com/category/n
e-2-0-packet-tracer-activity-lab-
answers/)

NS 1.0 – Lab Answers


(https://infraexam.com/category/n
s-1-0-lab-answers/)

NS 1.0 – Packet Tracer Activity


Lab Answers
(https://infraexam.com/category/n
s-1-0-packet-tracer-activity-lab-
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;
}

compilation error in LINE II


runtime error at LINE I
the program outputs 1, 4, 6, 7, 8, 9,

the program outputs 8, 9, 7, 6, 4, 1,


compilation error in LINE I
the program outputs 1, 4, 7, 8, 9,

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;
}

compilation error in LINE I


the program outputs 1, 1, 0, 2, -1, 0,

the program outputs -7, -5, -1, 1, 5, 7,


runtime error at LINE I
the program outputs 0, -1, 2, 0, 1, 1 NEW
compilation error in LINE II


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;
}

compilation error in LINE II


runtime error at LINE I
you shouldn’t call inplace_merge function on non ordered v1

vector ;;;;

the program outputs 4, 4, 0, 8, 9, 7, 1,


compilation error in LINE I
the program outputs 4, 4, 0, 8, 9, 7,

the program outputs 4, 4, 8, 9, 7, 1,


AD

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

deque < int > d1(s1.rbegin (), s1.rend ());


reverse (v1.begin ()v1.end ());
reverse (d1.begin (),d1.end ()); //LINE II 
for_each(s1.begin(),s1.end(), Out < int >(cout))
for_each(d1.begin(),d1.end(), Out < int >(cout))
return 0;
}

compilation error in LINE I


the program outputs 3, 4, 5, 5, 4, 3,

the program outputs 3, 4, 5, 3, 4, 5, 3, 4, 5,


runtime error at LINE I
compilation error in LINE II
the program outputs 3, 4, 5, 3, 4, 5,
AD

7.

What happen if you try to compile and run this program?

#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

the program outputs 3.14159, 3.14, 3.50,


the program outputs 3.14159, 3.140, 3.500, 
compilation error in LINE II
the program outputs 3.14159, 3.14, 3.5,
runtime error at LINE I
compilation error in LINE I
AD

8.

What happen if you try to compile and run this program?

#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;
}

compilation error in LINE II


the program outputs 1.5

the program outputs 2.5


compilation error in LINE I
the program outputs 2
runtime error at LINE I

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;
}

compilation error in LINE II


program outputs: 1, 4, 6, 7, 8, 9,

program outputs: 1, 4, 6, 7, 8, 9, 10,

program outputs: 1, 4, 9, 10,


runtime error at LINE II
program outputs: 1, 10,
compilation error in LINE I
AD

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;
}

compilation error in LINE II


program outputs 1, 4, 7,

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

runtime error at LINE I


the program outputs 0, 3, 5, 6, 8, 7,
runtime error at LINE II 
the program outputs 0, 0, 3, 5, 6, 8, 7,
compilation error in LINE I
compilation error in LINE II
the program outputs 7, 8, 6, 8, 7,
AD

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

v1.insert (v1.end (), A (0));


print (v1.begin (), v1.end()) << endl;

return 0;
}

compilation error in LINE I


compilation error in LINE II
runtime error at LINE II
program outputs: 1, 5, 3, 3, 5, 6, 0,

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;
}

runtime error at LINE I NEW

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;

SomethingSpecial ():value (0){}


SomethingSpecial (double value):value (value){}
SomethingSpecial operator+= (SomethingSpecial &
{
SomethingSpecial result;
result.value = value + _Right.value;
}
};
template < typename T > class Pocket
{
T value;

public:
Pocket(){}
Pocket (T value);
T getValue ()
{
return value;
}
void add (T _Right)
{
value += _Right;
}
}; NEW

template < class T > Pocket < T >::Pocket (T value


int
main() 
{
Pocket < double >a (3); //LINE I
Pocket < SomethingSpecial > n;
n.add(SomethingSpecial ()); //LINE II
cout << a.getValue () << ", ";
a.add (3);
cout << a.getValue ();
return 0;
}

compilation error in LINE I


runtime error at LINE I
program outputs: 3, 6,

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;
}

the program outputs 2, 5, 7, 8, 10, 9,


runtime error at LINE I
compilation error in LINE I
the program outputs 8, 9, 7, 6, 4, 1,

the program outputs 1, 4, 6, 7, 8,


compilation error in LINE II

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;
}

compilation error in LINE II


the program outputs 4, 1,
runtime error at LINE II
compilation error in LINE I
the program outputs 1, 4, 0, 0, 0, 0, 0,

the program outputs 0, 0, 0, 0, 0, 0, 0,


AD

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;
}

runtime error at LINE I


compilation error in LINE I
the program outputs 2, 5, 7, 8, 10, 9,

the program outputs 0, 0, 0, 0, 0, 0,

the program outputs 9, 10, 8, 7, 5, 2,


compilation error in LINE II

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

set<Pocket> s1(mynumbers1, mynumbers1 + 6);


sort(d1.begin(), d1.end());
sort(mynumbers1, mynumbers1 +5);

sort(mynumbers2, mynumbers2 + 4);
cout << includes(d1.begin(), d1.end(), mynumbers
<<includes(s1.begin(), s1.end, mynumbers2,my
return 0;
}

runtime error at LINE I


compilation error in LINE II
compilation error in LINE I
the program outputs 8, 9, 7, 6, 3, 2, 4
the program outputs 1, 0

the program outputs 0, 1

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;
}

the program outputs 18, 20, 16, 14, 10, 4, NEW

runtime error at LINE I


the program outputs 4, 10, 14, 16, 18, 20,
compilation error in LINE I 
the program outputs 32, 36, 28, 24, 16, 4,
compilation error in LINE II

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;
}

compilation error in LINE I


the program outputs 8, 9, 7, 6, 4, 1,

the program outputs 8, 9, 7, 6, 4, 4,

the program outputs 8, 9, 7, 6, 4, 1, 4,


compilation error in LINE I
runtime error at LINE I

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;
}

runtime error at LINE II


runtime error at LINE I
compilation error in LINE II
the program outputs 6, 4, 1,

the program outputs 8, 9, 7, 6,

the program outputs 4, 1,


compilation error in LINE I

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

Compare(const Pocket<double>& _Left, const Pocke


{
return int (_Left.getValue()) <int(_Right.getV

}
int
main()
{
double mynumbers[] = {1.11, 3.13, 2.12, 5.15, 6.
vector <double> v1 (mynumbers, mynumbers + 6); /
stable_sort(v1.begin(), v1.end(), Compare); //LI
for_each(v1.begin(),v1.end(), printer);
return 0;
}

the program outputs 1.11, 3.13, 2.12, 5.15, 6.16,

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;
}

runtime error at LINE I


compilation error in LINE I
program output: found, 8, 9, 7, 6, 4, 1, 1, 4, 6, 7,

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;
}

compilation error in LINE II


compilation error in LINE I
runtime error at LINE I
the program outputs 31.23, 31.23, 63.23,

the program outputs 31.23, 037.27, 77.27,

the program outputs 31.23, 31.27, 77.27,

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;
}

the program outputs 0


compilation error in LINE II
runtime error at LINE II
the program outputs 7
compilation error in LINE I
the program outputs 7.000

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;
}

compilation error in LINE II


runtime error at LINE I
the program output: 31, 31, ,

the program output: 31, 31, 63


compilation error in LINE I
the program output: 31, 31, 3f,
NEW


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;
}

the program output: 1,


compilation error in LINE I
runtime error at LINE I
the program output: 8,

the program output: 4,


compilation error in LINE II

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;
}

compilation error in LINE II


compilation error in LINE I
the program output: 1, 4, 4, 6, 7, 8,

the program output: 1, 4, 4, 6, 7, 8, 0,


runtime error at LINE I
the program output: 4, 8, 3, 1,

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;
}

compilation error in LINE III


compilation error in LINE II
program outputs: one, , four, six, seven, eight,

nine,
program outputs: seven element, one, , four, six,

seven, eight, nine, 7


program outputs: one, , four, six, seven, eight,

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;
}

compilation error in LINE II

the program outputs 1.5


runtime error at LINE II
the program outputs 2.5

the program outputs 3.5


compilation error in LINE I

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;
}

compilation error in LINE I


program outputs: Found at position:
runtime error at LINE I
compilation error in LINE II
program outputs: Found at position: 1

program outputs: Found at position: 2

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;
}

both vectors v1 and v2 have the same capacity

program outputs: -1, 10

program outputs: -1, 0

program outputs: 0, -1

value returned by size() is the same for vectors v1 and v2

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;
}

compilation error in LINE II


program outputs i, j, k, jk, q, q,

program outputs i, j, k, jk, NEW

compilation error in LINE I


program outputs i, j, k, jk, q,
runtime error at LINE I 
36. What happens if you try to compile and run this program ?

#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;
}

compilation error in LINE I


runtime error at LINE I
the program outputs 2
compilation error in LINE II
the program outputs 4

the program outputs 1


37. Which of the following examples show(s) the proper way to
create a new queue container assuming all necessary
declarations have been performed. Choose all that apply:

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;
}

the program outputs 31, 31, 3f,


compilation error in LINE II
runtime error at LINE I
compilation error in LINE I
the program outputs 31, 31, 63

the program outputs 31, 0x1f, 3f,

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;
}

the program outputs: 0


runtime error at LINE I
compilation error in LINE I
the program outputs 3
NEW
compilation error in LINE III
compilation error in LINE II
the program outputs 4

41. What happens when you attempt to compile and run the
code?

#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

compilation error in LINE I 


program outputs 8, 9, 7, 1, 4, 6, 7, 8, 9, 6, 4, 1,
compilation error in LINE II
runtime error at LINE I
program outputs: 8, 9, 7, 1, 4, 6, 7, 8, 9,

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

cout << 31 << ", ";


cout.unsetf (ios::showbase); //LINE II

cout << 63 << ", ";
return 0;
}

the program outputs 31, 31, 3f,


compilation error in LINE II
runtime error at LINE I
compilation error in LINE I
the program outputs 31, 31, 63

the program outputs 31, 0x1f, 3f,

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;
}

the program outputs 5, 4, 3, 2, 6,


compilation error in LINE II

the program outputs 4, 3, 2, 1, 5,


runtime error at LINE I

the program outputs 4, 3, 2, 1, 6,


compilation error in LINE I
44. What happens if you try to compile and run this program?

#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;
}

compilation error in LINE I


the program outputs 31, 31, 77,

the program outputs 31, 31, 63,


runtime error at LINE I
compilation error in LINE II
the program outputs 31, 037, 77, NEW


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;
}

runtime error at LINE I


compilation error in LINE I
the program outputs 4 5 6, 4 5 6,

the program outputs 4 5 6 4 5 6,


compilation error in LINE II
the program outputs 4, 5, 6, 4, 5, 6,

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;
}

the program outputs 8, 9, 7, 6, 4, 4,


runtime error at LINE I
the program outputs 8, 9, 7, 6, 4, 1,
compilation error in LINE II
the program outputs 8, 9, 7, 6, 4, 1, 4,
compilation error in LINE I

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;
}

runtime error at LINE I

the program outputs 0, 0, 0, 0, 0, 0,


the program outputs 0, 3, 5, 6, 8, 7,
compilation error in LINE I
compilation error in LINE II

the program outputs 1, 4, 6, 7, 9, 8,

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;
}

the program outputs 7.0000

the program outputs 7

the program outputs 0


compilation error in LINE II
compilation error in LINE I
runtime error at LINE II

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;
}

the program outputs true, false, true,


runtime error at LINE I
the program outputs false, false, true,
compilation error in LINE I
the program outputs 1, 0, 1,

 CPP : All Parts

CPP – Advanced Programming in C++ : All Parts


(https://infraexam.com/c-institute/cpp-advanced-programming-in

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/)

Summary Test (https://infraexam.com/c-institute/cpp-advanced-progr


in-c/advanced-c-summary-test/)

Final Test (https://infraexam.com/c-institute/cpp-advanced-programm


c/advanced-c-final-test/)

Copyright © 2024 InfraExam

NEW

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy