51. Which of the following operator can be overloaded?
52. How to store the large objects in c++ if it extends its allocated memory?
53. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("microsoft");
string::reverse_iterator r;
for (r = str.rbegin() ; r < str.rend(); r++ )
cout << *r;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("microsoft");
string::reverse_iterator r;
for (r = str.rbegin() ; r < str.rend(); r++ )
cout << *r;
return 0;
}
54. How to declare the complex number?
55. Given the following C++ code. How would you define the < operator for Box class so that when boxes b1 and b2 are compared in if block the program gives correct result?
#include <iostream>
#include <string>
using namespace std;
class Box
{
int capacity;
public:
Box(){}
Box(double capacity){
this->capacity = capacity;
}
};
int main(int argc, char const *argv[])
{
Box b1(10);
Box b2 = Box(14);
if(b1 < b2){
cout<<"Box 2 has large capacity.";
}
else{
cout<<"Box 1 has large capacity.";
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class Box
{
int capacity;
public:
Box(){}
Box(double capacity){
this->capacity = capacity;
}
};
int main(int argc, char const *argv[])
{
Box b1(10);
Box b2 = Box(14);
if(b1 < b2){
cout<<"Box 2 has large capacity.";
}
else{
cout<<"Box 1 has large capacity.";
}
return 0;
}
56. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class sample
{
public:
sample(int i) : m_i(i) { }
public:
int operator()(int i = 0) const
{
return m_i + i;
}
operator int () const
{
return m_i;
}
private:
int m_i;
friend int g(const sample&);
};
int f(char c)
{
return c;
}
int main()
{
sample f(2);
cout << f(2);
return 0;
}
#include <iostream>
using namespace std;
class sample
{
public:
sample(int i) : m_i(i) { }
public:
int operator()(int i = 0) const
{
return m_i + i;
}
operator int () const
{
return m_i;
}
private:
int m_i;
friend int g(const sample&);
};
int f(char c)
{
return c;
}
int main()
{
sample f(2);
cout << f(2);
return 0;
}
57. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("example.");
str.front() = 'E';
cout << str << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("example.");
str.front() = 'E';
cout << str << endl;
return 0;
}
58. Which container in c++ will take large objects?
59. How many types of models are available to create the user-defined data type?
60. Which concepts does the Pre Increment use?
Read More Section(Classes and Objects in C plus plus)
Each Section contains maximum 100 MCQs question on Classes and Objects in C plus plus. To get more questions visit other sections.