Here is a listing of C++ language interview questions on “Modifying Sequence Algorithms” along with answers, explanations and/or solutions:
1. What is the use of middle parameter in the rotate method?
a) Marks the begining of a sequence
b) Marks the ending of a sequence
c) Marks the elements in a sequence
d) Marks the digits in a sequence
View Answer
Explanation: Forward iterator pointing to the element within the range and that can be moved to the first position in the range.
2. What kind of object is modifying sequence algorithm?
a) Function template
b) Class template
c) Method
d) Iterator
View Answer
Explanation: It is a group of functions and implemented under algorithm header file.
3. How the sequence of objects can be accessed?
a) Iterators
b) Pointers
c) Both Iterators & Pointers
d) Library
View Answer
Explanation: A range is any sequence of objects that can be accessed through iterators or pointers, such as an array or an instance of some of the STL containers.
4. What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector (5);
fill (myvector.begin(), myvector.begin() + 4, 5);
fill (myvector.begin() + 3,myvector.end() - 2, 8);
for (vector<int> :: iterator it = myvector.begin();
it != myvector.end(); ++it)
cout << ' ' << *it;
return 0;
}
a) 5 5 5 5 0
b) 8 8 8 8 0
c) 5 8 5 8 0
d) 5 5 5 5 5
View Answer
Explanation: In this program, We filled up all the vector values by using fill method.
Output:
$ g++ msa.cpp $ a.out 5 5 5 5 0
5. 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;
}
a) 10
b) 10 40
c) 10 99 40 99
d) 99 40 10
View Answer
Explanation: In this program, We are swapping the certain values in two vectors by using iter_swap.
Output:
$ g++ msa1.cpp $ a.out 10 99 40 99
6. What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int op_increase (int i)
{
return ++i;
}
int main ()
{
vector<int> a;
vector<int> b;
for (int i = 1; i < 4; i++)
a.push_back (i * 10);
b.resize(a.size());
transform (a.begin(), a.end(), b.begin(), op_increase);
transform (a.begin(), a.end(), b.begin(), a.begin(), plus<int>());
for (vector<int> :: iterator it = a.begin(); it != a.end(); ++it)
cout << ' ' << *it;
return 0;
}
a) 21
b) 41
c) 61
d) 21 41 61
View Answer
Explanation: In this program, We allocated the values to the vector and then by using transform function, We increased the values.
Output:
$ g++ msa2.cpp $ a.out 21 41 61
7. 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;
}
a) 10 20 30
b) 10 30 30 10 10
c) 10 20 30 30
d) 40 20 10 20
View Answer
Explanation: In this program, We removed the values in the vector by using the remove method.
Output:
$ g++ msa3.cpp $ a.out 10 30 30 10 10
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 ,40 };
int * p;
p = find (myints, myints + 4, 30);
--p;
cout << *p << '\n';
return 0;
}
a) 10
b) 20
c) 30
d) 40
View Answer
Explanation: In this program, We used the find method to find the value before 20.
Output:
$ g++ msa4.cpp $ a.out 20
9. How many kind of operation can be applied to transform method in c++?
a) 1
b) 2
c) 3
d) 4
View Answer
Explanation: There are two kinds of operations. They are unary and binary operation.
10. What operator is used to remove the dupplicates in the range?
a) )
b) ^
c) %
d) ==
View Answer
Explanation: The function uses operator== to compare the pairs of elements.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Practice Programming MCQs
- Check Computer Science Books
- Practice Computer Science MCQs
- Check Programming Books
- Check C++ Books