Select an option to see the answer and solution.
Standard Template Library (STL) in C++
practice.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
109
Questions
3/6
Page
Pick an option on a question to see the right answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("%lf\n", fmod (5.3, 2) );
printf ("%lf\n", fmod (18.5, 4.2) );
return 0;
}Select an option to see the answer and solution.
#include <typeinfo>
#include <iostream>
using namespace std;
class shape
{
public:
virtual void myvirtualfunc() const {}
};
class mytriangle: public shape
{
public:
virtual void myvirtualfunc() const
{
};
};
int main()
{
shape shape_instance;
shape &ref_shape = shape_instance;
try
{
mytriangle &ref_mytriangle = dynamic_cast(ref_shape);
}
catch (bad_cast)
{
cout << "Caught: bad_cast exception\n";
}
return 0;
} Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector;
for (int i = 1; i < 6; ++i)
myvector.push_back(i);
reverse(myvector.begin(), myvector.end());
for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it)
cout << ' ' << *it;
return 0;
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
v.assign( 10, 42 );
for (int i = 0; i < v.size(); i++)
{
cout << v[i] << " ";
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char s[] = "365.24 29.53";
char* p;
double d1, d2;
d1 = strtod (s, &p);
d2 = strtod (p, NULL);
printf ("%.2f\n", d1/d2);
return 0;
}Select an option to see the answer and solution.
#include <iostream>
#include <list>
#include <queue>
using namespace std;
int main()
{
queue<char> q;
q.push('a');
q.push('b');
q.push('c');
cout << q.front();
q.pop();
cout << q.front();
q.pop();
cout << q.front();
q.pop();
}Select an option to see the answer and solution.
#include <list>
#include <string>
#include <iostream>
using namespace std ;
typedef list<string> LISTSTR;
int main()
{
LISTSTR :: iterator i;
LISTSTR test;
test.insert(test.end(), "one");
test.insert(test.end(), "two");
LISTSTR test2(test);
LISTSTR test3(3, "three");
LISTSTR test4(++test3.begin(),
test3.end());
cout << "test:";
for (i = test.begin(); i != test.end(); ++i)
cout << " " << *i << endl;
cout << "test:";
for (i = test2.begin(); i != test2.end(); ++i)
cout << " " << *i << endl;
cout << "test:";
for (i = test3.begin(); i != test3.end(); ++i)
cout << " " << *i << endl;
cout << "test:";
for (i = test4.begin(); i != test4.end(); ++i)
cout << " " << *i << endl;
}Select an option to see the answer and solution.
Select an option to see the answer and solution.