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;
}

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;
}

bool operator<(Box b)
{
    return this->capacity < b.capacity ? true : false;
}

bool operator<(Box b)
{
    return this->capacity > b.capacity ? true : false;
}

bool operator<(Box b)
{
    return  b1 > b2 ? true : false;
}

bool operator<(Box b)
{
    return this < b ? true : false;
}

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;
}

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;
}

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.