adplus-dvertising

Welcome to the Classes and Operator Overloading in C++ MCQs Page

Dive deep into the fascinating world of Classes and Operator Overloading in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Operator Overloading in C++, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Operator Overloading in C++, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Classes and Operator Overloading in C++. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Classes and Operator Overloading in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Classes and Operator Overloading in C++ MCQs | Page 9 of 39

Explore more Topics under Object Oriented Programming Using C++

Q81.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class Box
    {
        double width;
        public:
        friend void printWidth( Box box );
        void setWidth( double wid );
    };
    void Box::setWidth( double wid )
    {
        width = wid;
    }
    void printWidth( Box box )
    {
        box.width = box.width * 2;
        cout << "Width of box : " << box.width << endl;
    }
    int main( )
    {
        Box box;
        box.setWidth(10.0);
        printWidth( box );
        return 0;
   }
Discuss
Answer: (d).20
Q82.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class sample 
    {
        int width, height;
        public:
        void set_values (int, int);
        int area () {return (width * height);}
        friend sample duplicate (sample);
    };
    void sample::set_values (int a, int b) 
    {
        width = a;
        height = b;
    }
    sample duplicate (sample rectparam)
    {
        sample rectres;
        rectres.width = rectparam.width * 2;
        rectres.height = rectparam.height * 2;
        return (rectres);
    }  
    int main ()  
    {
        sample rect, rectb;
        rect.set_values (2, 3);
        rectb = duplicate (rect);
        cout << rectb.area();
        return 0;
    }
Discuss
Answer: (c).24
Q83.
What is the output of this program?
    #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;
    }
Discuss
Answer: (d).36
Q84.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class base
    {
        int val1, val2;
        public:
        int get()
 {
            val1 = 100;
            val2 = 300;
 }
        friend float mean(base ob);
    };
    float mean(base ob)
    {
        return float(ob.val1 + ob.val2) / 2;
    }
    int main()
    {
        base obj;
        obj.get();
        cout << mean(obj);
        return 0;
    }
Discuss
Answer: (a).200
Q85.
What is the output of this program?
    #include <iostream>
    using namespace std;
    class sample
    {
        private:
        int a, b;
        public:
        void test()
        {
            a = 100;
            b = 200;
        }
        friend int compute(sample e1);
    };
    int compute(sample e1)
    {
        return int(e1.a + e1.b) - 5;
    }
    int main()
    {
        sample e;
        e.test();
        cout  << compute(e);
        return 0;
    }
Discuss
Answer: (d).295
Discuss
Answer: (c).A friend function may or may not be a member of another class
Q87.
Where does keyword β€˜friend’ should be placed?
Discuss
Answer: (a).function declaration
Q88.
How to store the large objects in c++ if it extents its allocated memory?
Discuss
Answer: (a).memory heap
Q89.
When we are using heap operations what do we need to do to save the memory?
Discuss
Answer: (b).delete the objects after processing
Q90.
Which container in c++ will take large objects?
Discuss
Answer: (c).vector

Suggested Topics

Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!