Select an option to see the answer and solution.
C++ miscellaneous
practice.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
1,008
Questions
3/51
Page
Pick an option on a question to see the right answer and solution.
#include<iostream>
using namespace std;
class X
{
int m;
public:
X() : m(10)
{
}
X(int mm): m(mm)
{
}
int getm()
{
return m;
}
};
class Y : public X
{
int n;
public:
Y(int nn) : n(nn) {}
int getn() { return n; }
};
int main()
{
Y yobj( 100 );
cout << yobj.getm() << " " << yobj.getn() << endl;
}Select an option to see the answer and solution.
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<8> b1(95);
bitset<8> b2(45);
cout<<~b1<<endl;
cout<<(b1|b2)<<endl;
cout<<(b1&b2)<<endl;
}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 <functional>
#include <numeric>
using namespace std;
int myfunction (int x, int y)
{
return x + 2 * y;
}
struct myclass
{
int operator()(int x, int y)
{
return x + 3 * y;
}
} myobject;
int main ()
{
int init = 100;
int numbers[] = {10, 20, 30};
cout << accumulate(numbers, numbers + 3, init);
cout << endl;
}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 <complex>
using namespace std;
int main()
{
complex <double> cn(3.0, 5.0);
cout<<"Complex number is: "<<real(cn)<<" + "<<imag(cn)<<"i"<<endl;
return 0;
}Select an option to see the answer and solution.
#include <iostream>
using namespace std;
class poly
{
protected:
int width, height;
public:
void set_values(int a, int b)
{
width = a; height = b;
}
};
class Coutput
{
public:
void output(int i);
};
void Coutput::output(int i)
{
cout << i;
}
class rect:public poly, public Coutput
{
public:
int area()
{
return(width * height);
}
};
class tri:public poly, public Coutput
{
public:
int area()
{
return(width * height / 2);
}
};
int main()
{
rect rect;
tri trgl;
rect.set_values(3, 4);
trgl.set_values(4, 5);
rect.output(rect.area());
trgl.output(trgl.area());
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 <memory>
#include <string>
using namespace std;
int main ()
{
string numbers[] = {"steve", "jobs"};
pair <string*, ptrdiff_t> result = get_temporary_buffer<string>(2);
if (result.second>0)
{
uninitialized_copy ( numbers, numbers + result.second, result.first );
for (int i = 0; i < result.second; i++)
cout << result.first[i] << " ";
return_temporary_buffer(result.first);
}
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 <string>
#include <iostream>
using namespace std;
void string_permutation( string& orig, string& perm )
{
if (orig.empty())
{
cout<<perm<<endl;
return;
}
for (int i = 0; i < orig.size(); ++i)
{
string orig2 = orig;
orig2.erase(i, 1);
string perm2 = perm;
perm2 += orig.at(i);
string_permutation(orig2, perm2);
}
}
int main()
{
string orig = "ter";
string perm;
string_permutation(orig, perm);
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.
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> first;
first.assign (7,100);
vector<int>::iterator it;
it=first.begin()+1;
int myints[] = {1776,7,4};
cout << int (first.size()) << '\n';
return 0;
}Select an option to see the answer and solution.