My Report

C++ Programming Mock Test 6


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement
 10%

Question 1 of 10

1. Why do we need to handle exceptions?

Question 1 of 10

Question 2 of 10

2. What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
class A
{
	float d;
   public:
	virtual void func(){
		cout<<"Hello this is class A\n";
	}
};

class B: public A
{
	int a = 15;
   public:
	void func(){
		cout<<"Hello this is class B\n";
	}
};

int main(int argc, char const *argv[])
{
	A *a = new A();
	B b;
	a = &b;
	a->func();
	return 0;
}

Question 2 of 10

Question 3 of 10

3. What will be the output of the following C++ code?

  
    #include <iostream>
    #include <exception>
    #include <typeinfo>
    using namespace std;
    class Test1
    {    
        virtual int  Funct() 
        {
        }
    };
    int main ()
    {
        try 
        {
            Test1 * var = NULL;
            typeid (*var);
        }
        catch (std::exception& typevar)
        {
            cout << "Exception: " << typevar.what() << endl;   
        }
        return 0;
    }

Question 3 of 10

Question 4 of 10

4. Which function is invoked when we try to throw an exception that is not supported by a function?

Question 4 of 10

Question 5 of 10

5. To which of the following access specifiers are applicable?

Question 5 of 10

Question 6 of 10

6. What will be the output of the following C++ code?

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class A
{
	int a;
    public:
	A(){}
};
class B: public A
{
	int b;
    public:
	B(){}
};

void func()
{
	B b;
	throw b;
}
int main()
{
	try{
		func();
	}
	catch(B *b){
		cout<<"Caught B Class\n";
	}
	catch(A a){
		cout<<"Caught A Class\n";
	}
}

Question 6 of 10

Question 7 of 10

7. What will be the output of the following C++ code?

  
    #include <iostream>
    #include <exception>
    #include <cstdlib>
    using namespace std;
    void myterminate () 
    {
        cerr << "terminate handler called";
        abort();
    }
    int main (void) 
    {
        set_terminate (myterminate);
        throw 0; 
        return 0;
    }

Question 7 of 10

Question 8 of 10

8. Where exception are handled?

Question 8 of 10

Question 9 of 10

9. Uncaught exception leads to ______________

Question 9 of 10

Question 10 of 10

10. What is the order of Destructors call when the object of derived class B is declared, provided class B is derived from class A?

Question 10 of 10


 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.