My Report

C++ Programming Practice 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

1. Which of the following is correct about Functors?

2. By using which operator does point to next element is represent in
iterator?

3. Which function is used to return the minimum element in the range?

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

 
    #include <iostream> 
    #include <algorithm>
    using namespace std;
    int main () 
    {
        int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};  
        int* pbegin = myints;                      
        int* pend = myints + sizeof(myints) / sizeof(int);
        pend = remove (pbegin, pend, 20);      
        for (int* p = pbegin; p != pend; ++p)
            cout << ' ' << *p;
        return 0;
    }

5. Which type of relationship is modelled by Association?

6. What is the use of make_heap in the heap operation?

7. Which container is best to keep the collection of distinct elements?

8. 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(); 
    ptr = advance(ptr, 2);
    cout << *ptr << endl; 
    return 0; 
} 

9. What is the use of random_shuffle() function of STL algorithm?

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

    #include <iostream>
    #include <functional>
    #include <algorithm>
    using namespace std;
    int main ()
    {
        int numbers[] = {10, -20, -30, 40, -50};
        int cx;
        cx = count_if ( numbers, numbers + 5, bind2nd(less<int>(), 0) );
        cout << cx;
        return 0;
    }

 

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.