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 is the header file used for declaring the standard library algorithms?

Question 1 of 10

Question 2 of 10

2. Which function can be used to find the sum of a vector container?

Question 2 of 10

Question 3 of 10

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

#include<iostream> 
#include<iterator> 
#include<vector> 
using namespace std; 
int main() 
{ 
    vector<int> ar = { 1, 2, 3, 4, 5 }; 
    vector<int>::iterator ptr = ar.begin(); 
    advance(ptr, 2);
    cout << *ptr << endl; 
    return 0; 
}

Question 3 of 10

Question 4 of 10

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

  
    #include <iostream>
    #include <memory>
    #include <algorithm>
    using namespace std;
    int main ()
    {
        int numbers[] = {1, 5, 4, 5};
        pair <int*, ptrdiff_t> result = get_temporary_buffer<int>(4);
        if (result.second > 0)
        {
            uninitialized_copy (numbers, numbers + result.second, result.first);
            sort (result.first, result.first + result.second);
            for (int i = 0; i < result.second; i++)
                cout << result.first[i] << " ";
            return_temporary_buffer (result.first);
        }
        return 0;
    }

Question 4 of 10

Question 5 of 10

5. Which header file is used to manipulate the allocater?

Question 5 of 10

Question 6 of 10

6. 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, 30, 20, 10, 10, 20};
        int mycount = count (myints, myints + 8, 10);
        cout << mycount;
        vector<int> myvector (myints, myints + 8);
        mycount = count (myvector.begin(), myvector.end(), 20);
        cout << mycount;
        return 0;
    }

Question 6 of 10

Question 7 of 10

7. Unordered map is implemented using _________________

Question 7 of 10

Question 8 of 10

8. If i1 is Input Iterator and i2 is Output Iterator, then which of the following things are correct?

i) cout<<*i1;
ii) i2 can be used with == operator
iii) *i1 = 1
iv) i2--

Question 8 of 10

Question 9 of 10

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

  
    #include <vector>
    #include <iostream>
    #include <typeinfo>
    #include <stdexcept>
    using namespace std;
    int main()
    {
        vector<int> vec;
        vec.push_back(10);
        int i = vec[100];
        try {
            i = vec[0];
            cout << i << endl;
        }
        catch (exception &e)
        {
            cout << "Caught: " << e.what( ) << endl;
            cout << "Type: " << typeid( e ).name( ) << endl;
        }
        catch (...) 
        {
            cout << "Unknown exception: " << endl;
        }
        return 0;
    }

Question 9 of 10

Question 10 of 10

10. Which type of relationship is modelled by Association?

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.