21. What will be the output of the following C++ code?
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
vector <int> v = {1,5,23,90,15,35};
make_heap(v.begin(),v.end());
cout<<v.front();
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
vector <int> v = {1,5,23,90,15,35};
make_heap(v.begin(),v.end());
cout<<v.front();
}22. Which is the following is syntactically correct for vector<int> v?
23. What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 4.0);
auto cnj = conj(cn);
cout<<"Conjugate of "<<real(cn)<<"+("<<imag(cn)<<")i is: "<<real(cnj)<<"
+("<<imag(cnj)<<")i"<<endl;
return 0;
}
#include <iostream>
#include <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 4.0);
auto cnj = conj(cn);
cout<<"Conjugate of "<<real(cn)<<"+("<<imag(cn)<<")i is: "<<real(cnj)<<"
+("<<imag(cnj)<<")i"<<endl;
return 0;
}24. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class p
{
protected:
int width, height;
public:
void set_values (int a, int b)
{
width = a; height = b;
}
virtual int area (void) = 0;
};
class r: public p
{
public:
int area (void)
{
return (width * height);
}
};
class t: public p
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
r rect;
t trgl;
p * ppoly1 = ▭
p * ppoly2 = &trgl;
ppoly1->set_values (4, 5);
ppoly2->set_values (4, 5);
cout << ppoly1 -> area() ;
cout << ppoly2 -> area();
return 0;
}
#include <iostream>
using namespace std;
class p
{
protected:
int width, height;
public:
void set_values (int a, int b)
{
width = a; height = b;
}
virtual int area (void) = 0;
};
class r: public p
{
public:
int area (void)
{
return (width * height);
}
};
class t: public p
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
r rect;
t trgl;
p * ppoly1 = ▭
p * ppoly2 = &trgl;
ppoly1->set_values (4, 5);
ppoly2->set_values (4, 5);
cout << ppoly1 -> area() ;
cout << ppoly2 -> area();
return 0;
}25. What kind of pattern is iterator pattern?
26. How many parameters are legal for non-type template?
27. What will be the output of the following C++ code?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
unsigned int i;
deque<int> mydeque;
mydeque.push_back (100);
mydeque.push_back (200);
mydeque.push_back (300);
for(deque<int> :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
{
}
mydeque.clear();
mydeque.push_back (110);
mydeque.push_back (220);
for(deque<int> :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
unsigned int i;
deque<int> mydeque;
mydeque.push_back (100);
mydeque.push_back (200);
mydeque.push_back (300);
for(deque<int> :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
{
}
mydeque.clear();
mydeque.push_back (110);
mydeque.push_back (220);
for(deque<int> :: iterator it = mydeque.begin(); it != mydeque.end(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}28. What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int myints[] = {10, 20, 30, 5, 15};
vector<int> v(myints, myints + 5);
make_heap (v.begin(), v.end());
pop_heap (v.begin(), v.end());
v.pop_back();
cout << v.front() << '\n';
return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int myints[] = {10, 20, 30, 5, 15};
vector<int> v(myints, myints + 5);
make_heap (v.begin(), v.end());
pop_heap (v.begin(), v.end());
v.pop_back();
cout << v.front() << '\n';
return 0;
}29. What will be the output of the following C++ code?
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
vector <int> v = {90, 47, 34, 23, 4, 35, 67};
auto it = is_heap_until(v.begin(), v.end());
for(auto i = v.begin(); i != it; i++)
cout<<*i<<" ";
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
vector <int> v = {90, 47, 34, 23, 4, 35, 67};
auto it = is_heap_until(v.begin(), v.end());
for(auto i = v.begin(); i != it; i++)
cout<<*i<<" ";
}30. What operator is used to remove the dupplicates in the range?
Read More Section(C plus plus miscellaneous)
Each Section contains maximum 100 MCQs question on C plus plus miscellaneous. To get more questions visit other sections.
- C plus plus miscellaneous - Section 1
- C plus plus miscellaneous - Section 2
- C plus plus miscellaneous - Section 3
- C plus plus miscellaneous - Section 4
- C plus plus miscellaneous - Section 5
- C plus plus miscellaneous - Section 7
- C plus plus miscellaneous - Section 8
- C plus plus miscellaneous - Section 9
- C plus plus miscellaneous - Section 10
- C plus plus miscellaneous - Section 11
