Iterators and Sequences Cpp MCQ

Errorlogger
0
1. How many categories are there in c++?
a) 2
b) 4
c) 5
d) 3



2. Which of the following can serve as random-access iterator?
a) Memory pointer
b) Object pointer
c) Class pointer
d) None of the mentioned



3. What kind of pattern is iterator pattern?
a) Design pattern
b) Sequence pattern
c) Adapter pattern
d) All of the mentioned



4. What is the output of this program?
  1.     #include <iostream>
  2.     #include <set>
  3.     using namespace std;
  4.     int main()
  5.     {
  6.         set<int> tst;
  7.         tst.insert(12);
  8.         tst.insert(21);
  9.         tst.insert(32);
  10.         tst.insert(31);
  11.         set<int> :: const_iterator pos;
  12.         for(pos = tst.begin(); pos != tst.end(); ++pos)
  13.         cout << *pos << ' ';
  14.         return 0;
  15.     }
a) 12 21 32 31
b) 12 21 31 32
c) 12 21 32
d) 12 21 31



5. What is the output of this program?
  1.     #include <iostream>
  2.     #include <vector>
  3.     #include<iterator>
  4.     using namespace std;
  5.     int main ()
  6.     {
  7.         vector<int> myvector;
  8.         for (int i = 1; i <= 10; i++)
  9.         myvector.push_back(i);
  10.         myvector.erase (myvector.begin() + 6);
  11.         myvector.erase (myvector.begin(), myvector.begin() + 4);
  12.         for (unsigned i = 0; i < myvector.size(); ++i)
  13.         cout << ' ' << myvector[i];
  14.         return 0;
  15.     }
a) 5 6 7 8 9
b) 5 6 8 9 10
c) 6 7 8 9 10
d) None of the mentioned



6. What is the output of this program?
  1.     #include <iostream>
  2.     #include <iterator>
  3.     #include <list>
  4.     using namespace std;
  5.     int main () 
  6.     {
  7.         list<int> mylist;
  8.         for (int i = 0; i < 10; i++) 
  9.         mylist.push_back (i * 10);
  10.         list<int> :: iterator it = mylist.begin();
  11.         advance (it, 5);
  12.         cout  << *it << endl;
  13.         return 0;
  14.     }
a) 30
b) 40
c) 50
d) 60



7. What is the output of this program?
  1.     #include <iostream>
  2.     #include <iterator>
  3.     #include <list>
  4.     using namespace std;
  5.     int main () 
  6.     {
  7.         list<int> firstlist, secondlist;
  8.         for (int i = 1; i <= 2; i++)
  9.         {  
  10.             firstlist.push_back(i); 
  11.             secondlist.push_back(i * 10); 
  12. 	}
  13.         list<int> :: iterator it;
  14.         it = firstlist.begin(); 
  15.         advance (it, 3);
  16.         copy (secondlist.begin(), secondlist.end(), inserter(firstlist, it));
  17.         for ( it = firstlist.begin(); it != firstlist.end(); ++it )
  18.             cout << *it << " ";
  19.         return 0;
  20.     }
a) 1 2 10 20
b) 10 20
c) 1 2
d) 1 10



8. What is the output of this program?
  1.     #include <iostream>
  2.     #include <iterator>
  3.     #include <list>
  4.     using namespace std;
  5.     int main () 
  6.     {
  7.         list<int> mylist;
  8.         for (int i = 0; i < 5; i++) 
  9.             mylist.push_back (i * 20);
  10.         list<int> :: iterator first = mylist.begin();
  11.         list<int> :: iterator last = mylist.end();
  12.         cout << distance(first, last) << endl;
  13.         return 0;
  14.     }
a) 20
b) 100
c) 5
d) None of the mentioned



9. In which type of semantics does c++ implements iterator?
a) Memory
b) Size
c) Pointer
d) None of the mentioned



10. By using which operator does point to next element is represent in
iterator?
a) ++
b) –
c) +-
d) None of the mentioned

Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !