41. Which header file is used for generating random numbers?
42. What will be the output of the following C++ code?
#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;
}
#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;
}
43. What will be the output of the following C++ code?
#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;
}
#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;
}
44. Which function is used to check whether a character is a number?
45. How many kinds of parameters are there in C++?
46. What will be the output of the following C++ code?
#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;
}
#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;
}
47. Which is used to get the input during runtime?
48. What is meant by pure virtual function?
49. What will be the output of the following C++ code?
#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;
}
#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;
}
50. What will be the output of the following C++ code?
#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;
}
#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;
}
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 2
- C plus plus miscellaneous - Section 3
- C plus plus miscellaneous - Section 4
- C plus plus miscellaneous - Section 5
- C plus plus miscellaneous - Section 6
- 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