adplus-dvertising

Welcome to the Derived Classes,Templates and Exception Handling in C++ MCQs Page

Dive deep into the fascinating world of Derived Classes,Templates and Exception Handling in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Derived Classes,Templates and Exception Handling 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 Derived Classes,Templates and Exception Handling 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 Derived Classes,Templates and Exception Handling 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 Derived Classes,Templates and Exception Handling in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Derived Classes,Templates and Exception Handling in C++ MCQs | Page 12 of 24

Q111.
What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
        int age=5;
        try 
        {
            if (age < 0)
                throw "Positive Number Required";
            cout  << age << "\n\n";
        }
        catch(const char* Message)
        {
            cout << "Error: " << Message;
        }
        return 0;
    }
Discuss
Answer: (a).5
Q112.
What is the output of this program?
    #include <iostream>
    using namespace std;
    double division(int a, int b)
    {
        if ( b == 0 )
        {
            throw "Division by zero condition!";
        }
        return (a / b);
    }
    int main ()
    {
        int x = 50;
        int y = 0;
        double z = 0;
        try 
        {
            z = division(x, y);
            cout << z << endl;
        }
        catch (const char* msg) 
        {
            cout << msg << endl;
        }
        return 0;
    }
Discuss
Answer: (c).Division by zero condition!
Q113.
What is the output of this program?
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
        double Op1 = 10, Op2 = 5, Res;
        char Op;
        try 
        {   
            if (Op != '+' && Op != '-' && Op != '*' && Op != '/')
                throw Op;
            switch(Op)
            {
            case '+':
                Res = Op1 + Op2;
                break;
            case '-':
                Res = Op1 - Op2;
                break;
            case '*':
                Res = Op1 * Op2;
                break;
            case '/':
                Res = Op1 / Op2;
                break;
             }
             cout << "\n" << Op1 << " " << Op << " "<< Op2 << " = " << Res;
         }
         catch (const char n)
         {
             cout << n << " is not a valid operator";
         }
         return 0;
    }
Discuss
Answer: (d).is not a valid operator
Q114.
What is the output of this program?
    #include<iostream>
    #include "math.h"
    using namespace std;
    double MySqrt(double d)
    {
        if (d < 0.0)
        throw "Cannot take sqrt of negative number";     
        return sqrt(d);
    }
    int main()
    {
        double d = 5;
        cout << MySqrt(d) << endl;
    }
Discuss
Answer: (b).2.236
Discuss
Answer: (a).We have to throw an exception
Q116.
What should present when throwing a object?
Discuss
Answer: (b).copy-constructor
Q117.
What can go wrong in resource management on c++?
Discuss
Answer: (d).All of the mentioned
Discuss
Answer: (b).It cannot be accessed by any standard mean
Q119.
What kind of error can arise when there is problem in memory?
Discuss
Answer: (a).Segmentation fault
Q120.
What is the output of this program?
    #include <iostream>
    #include <new>
    using namespace std;
    int main ()
    {
        int i, n;
        int * p;
        i = 2;
        p= new (nothrow) int[i];
        if (p == 0)
            cout << "Error: memory could not be allocated";
        else
 {
            for (n=0; n<i; n++)
            {
                p[n] = 5;
            }
            for (n = 0; n < i; n++)
                cout << p[n];
            delete[] p;
         }
         return 0;
    }
Discuss
Answer: (b).55

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!