C Plus Plus Miscellaneous - Study Mode
[#691] 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
}
Correct Answer
(D) Conjugate of 3+(4)i is: 3+(-4)i
[#692] 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 = &rect
p * ppoly2 = &trgl
ppoly1->set_values (4, 5)
ppoly2->set_values (4, 5)
cout << ppoly1 -> area()
cout << ppoly2 -> area()
return 0
}
Correct Answer
(D) 2010
[#693] 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 << '
'
return 0
}
Correct Answer
(C) Both 110 & 220
[#694] 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() << '
'
return 0
}
Correct Answer
(B) 20
[#695] 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<<" "
}
Correct Answer
(D) 90 47 34 23 4