Vidyalelo
C++ Programming · all questions

Classes and Objects in C++
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

251

Questions

13/13

Page

Pick an option on a question to see the right answer and solution.

What happens when objects s1 and s2 are added?
string s1 = "Hello";
string s2 = "World";
string s3 = (s1+s2).substr(5);

Select an option to see the answer and solution.

What does a mutable member of a class mean?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class test
{
    public:
    operator string () 
    {  
        return "Converted";
    }
};
int main()
{
    test t;
    string s = t;
    cout << s << endl;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream> 
#include <string>
#include <cstring>
using namespace std; 
int main()
{
	string s('a');
	cout<<s;
	return 0;
}

Select an option to see the answer and solution.

In the case of friend operator overloaded functions how many maximum object arguments a binary operator overloaded function can take?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class sample;
class sample1 
{
    int width, height;
    public:
    int area ()
    {
        return (width * height);}
        void convert (sample a);
    };
class sample 
{
    private:
    int side;
    public:
    void set_side (int a)
    { 
        side = a;
    }
    friend class sample1;
};
void sample1::convert (sample a) 
{
    width = a.side;
    height = a.side;
}
int main () 
{
    sample sqr;
    sample1 rect;
    sqr.set_side(6);
    rect.convert(sqr);
    cout << rect.area();
    return 0;
}

Select an option to see the answer and solution.

How many types are there in increment/decrement operator?

Select an option to see the answer and solution.

Which operator is having the highest precedence in c++?

Select an option to see the answer and solution.

How to unlimit the size of the stack?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Rect
{
    int x, y;
    public:
    void set_values (int,int);
    int area ()
    {
        return (x * y);
    }
};
void Rect::set_values (int a, int b) 
{
    x = a;
    y = b;
}
int main ()
{
    Rect recta, rectb;
    recta.set_values (5, 6);
    rectb.set_values (7, 6);
    cout << "recta area: " << recta.area();
    cout << "rectb area: " << rectb.area();
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class complex
{
    int i;
    int j;
    public:
    complex(){}
    complex(int a, int b)
    {
        i = a;
	j = b;
    }
     complex operator+(complex c)
     {
	complex temp;
	temp.i = this->i + c.i;
	temp.j = this->j + c.j;
	return temp;
    }
     void show(){
	cout<<"Complex Number: "<<i<<" + i"<<j<<endl;
    }
};
int main(int argc, char const *argv[])
{
    complex c1(1,2);
    complex c2(3,4);
    complex c3 = c1 + c2;
    c3.show();
    return 0;
}

Select an option to see the answer and solution.