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. How many types of guarantees are there in exception class can have?

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

Question 2 of 10

Question 3 of 10

3. In nested try-catch block, if the inner catch block gets executed, then______________

Question 3 of 10

Question 4 of 10

4. Which function is invoked when an unhandled exception is thrown?

Question 4 of 10

Question 5 of 10

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

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

void func(int a, int b)
{

	if(b == 0){
		throw "This value of b will make the product zero. " 
                      "So please provide positive values.\n";
	}
	else{
		cout<<"Product of "<<a<<" and  "<<b<<" is: "<<a*b<<endl;
	}
}

int main()
{
	try{
		func(5,0);
	}
	catch(const char* e){
		cout<<e;
	}
}

Question 5 of 10

Question 6 of 10

6. What is the use of clog?

Question 6 of 10

Question 7 of 10

7. What are the different types of exceptions?

Question 7 of 10

Question 8 of 10

8. What operation can be performed by destructor?

Question 8 of 10

Question 9 of 10

9. Pick out the correct statement for error handling alternatives.

Question 9 of 10

Question 10 of 10

10. What is a pure virtual function?

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.