My Report

C++ Programming Mock Test 9


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. What will be the output of the following C++ code?

 
    #include <iostream> 
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main ()
    {
        int first[] = {5, 10, 15, 20, 25};
        int second[] = {50, 40, 30, 20, 10};
        vector<int> v(10);
        vector<int> :: iterator it;
        sort (first, first + 5);
        sort (second, second + 5);
        it = set_union (first, first + 5, second, second + 5, v.begin());  
        v.resize(it-v.begin());
        for (it = v.begin(); it != v.end(); ++it)
            cout << ' ' << *it;
        cout << '\n';
        return 0;
    }

Question 1 of 10

Question 2 of 10

2. What are binary functors?

Question 2 of 10

Question 3 of 10

3. Which of the header file is used to implement algorithms provided by C++ STL?

Question 3 of 10

Question 4 of 10

4. Which operator is used to compare the elements in heap?

Question 4 of 10

Question 5 of 10

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

 
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main () 
    {
        vector<int> myvector;
        for (int i = 1; i < 6; ++i) 
            myvector.push_back(i);
        reverse(myvector.begin(), myvector.end());
        for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it)
            cout << ' ' << *it;
        return 0;
    }

Question 5 of 10

Question 6 of 10

6. Which of the following is correct about the map and unordered map?

Question 6 of 10

Question 7 of 10

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

    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main () 
    {
        int myints[] = {10, 20, 30, 5, 15};
        vector<int> v(myints, myints + 5);
        make_heap (v.begin(), v.end());
        pop_heap (v.begin(), v.end()); v.pop_back();
        v.push_back(99); push_heap (v.begin(), v.end());
        sort_heap (v.begin(), v.end());
        for (unsigned i = 0; i < v.size(); i++)
            cout << ' ' << v[i];
        return 0;
    }

Question 7 of 10

Question 8 of 10

8. Which of the following is correct about Functors?

Question 8 of 10

Question 9 of 10

9. What does the checked iterator allow you to find?

Question 9 of 10

Question 10 of 10

10. What are the two advantage of function objects than the function call?

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.