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. How many adaptors support the checked iterators?

2. What kind of execution does sequence point allow?

3. What is the correct syntax for declaring an allocator?

4. Which container is used to store elements as key-value pair?

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

#include <iostream>  
#include <algorithm> 
#include <vector> 

using namespace std;

bool IsOdd (int i) 
{ 
	return (i%2)==1; 
}

int main () 
{
  vector<int> v;

  for (int i=1; i<=10; ++i) 
  	v.push_back(i);

  vector<int>::iterator bound;
  bound = partition (v.begin(), v.end(), IsOdd);

  for (vector<int>::iterator it=v.begin(); it!=bound; ++it)
    cout << ' ' << *it;
  cout << '\n';

  for (vector<int>::iterator it=bound; it!=v.end(); ++it)
    cout << ' ' << *it;
  cout << '\n';

  return 0;
}

6. What is meant by sequence point?

7. What is meant by permutation in c++?

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

9. 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, 40, 50 };
        vector<int> myvector (4, 99);
        iter_swap(myints, myvector.begin());
        iter_swap(myints + 3,myvector.begin() + 2);
        for (vector<int> :: iterator it = myvector.begin(); 
            it != myvector.end(); ++it)
        cout << ' ' << *it;
        return 0;
    }

10. When does the next sequence point start?


 

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.