6) While there is a built-in pop_back() method for vectors, there is no built-in pop_front method. Suppose a program needs a pop_front() method that will remove the first element from the vector. For example if the original vector is [1, 2, 3, 4, 5], then after passing in this vector to pop_front() the new resulting vector will be [2, 3, 4, 5]. Which of the options below is the correct implementation of pop_front()? Group of answer choices D-) void pop_front(vector &v) { for(int i=0; i<(v.size()-1); i++) v[i+1] = v[i]; v.pop_back(); } C-) void pop_front(vector &v) { for(int i=0; i<(v.size()-1); i++) v[i] = v[i+1]; v.pop_back(); } B-) void pop_front(vector &v) { for(int i=0; i &v) { for(int i=0; i
6)
While there is a built-in pop_back() method for
Group of answer choices
D-)
void pop_front(vector<int> &v)
{
for(int i=0; i<(v.size()-1); i++)
v[i+1] = v[i];
v.pop_back();
}
C-)
void pop_front(vector<int> &v)
{
for(int i=0; i<(v.size()-1); i++)
v[i] = v[i+1];
v.pop_back();
}
B-)
void pop_front(vector<int> &v)
{
for(int i=0; i<v.size(); i++)
v[i+1] = v[i];
v.pop_back();
}
A-)
void pop_front(vector<int> &v)
{
for(int i=0; i<v.size(); i++)
v[i] = v[i+1];
v.pop_back();
}
7)
Suppose a program has the following vector:
[99, 23, 55, 71, 87, 64, 35, 42]
The goal is to remove the first, third, fifth, seventh, etc. elements from the vector
So after the program has finished, the vector should be:
[23, 71, 64, 42]
Which of the options below is the correct implementation of the program?
HINT: the first loop is being used to move the elements in the vector that we want to keep. The second loop is then being used to remove the elements that we want to get rid of.
Group of answer choices
B-)
for(int i=0; i<(v.size()/2-1); i++)
v[i] = v[2*i+1];
for(int i=0; i<(v.size()/2-1); i++)
v.pop_back();
C-)
for(int i=0; i<(v.size()/2); i++)
v[i] = v[2*i];
for(int i=0; i<(v.size()/2); i++)
v.pop_back();
A-)
for(int i=0; i<(v.size()/2-1); i++)
v[i] = v[2*i];
for(int i=0; i<(v.size()/2-1); i++)
v.pop_back();
D-)
for(int i=0; i<(v.size()/2); i++)
v[i] = v[2*i+1];
for(int i=0; i<(v.size()/2); i++)
v.pop_back();
8)
Suppose we want to create the following 3D (three dimensional) array:
Which of the options below contains the correct declaration for this array?
Group of answer choices
D-)arr[8][5][3];
B-)arr[5][8][3];
C-)arr[3][8][5];
A-)arr[3][5][8];
9)
While there is a built-in push_back() method for vectors, there is no built-in push_front method. Suppose a program needs a push_front() method that will add an item to the beginning of the vector. For example if the original vector is [2, 3, 4, 5], then after passing in this vector and the value 1 to push_front() the new resulting vector will be [1, 2, 3, 4, 5].
Which of the options below is the correct implementation of push_front()?
Group of answer choices
A-)
void push_front(vector<int> &v, int value)
{
v.push_back(-1);
for(int i=v.size()-1; i>0; i--)
v[i] = v[i-1];
v[0] = value;
}
C-)
void push_front(vector<int> &v, int value)
{
v.push_back(-1);
for(int i=v.size()-2; i>0; i--)
v[i] = v[i-1];
v[0] = value;
}
B-)
void push_front(vector<int> &v, int value)
{
v.push_back(-1);
for(int i=v.size()-1; i>0; i--)
v[i-1] = v[i];
v[0] = value;
}
D-)
void push_front(vector<int> &v, int value)
{
v.push_back(-1);
for(int i=v.size()-2; i>0; i--)
v[i-1] = v[i];
v[0] = value;
}
10)
A 4X4 2D array consists of 16 (sixteen) cells.
On this grid, there are two different ways to make four X’s diagonally. One of them is as follows:
X |
|
|
|
|
X |
|
|
|
|
X |
|
|
|
|
X |
Think about the second way to make the four x’s diagonally. All of the options below are cells that are part of the second diagonal EXCEPT:
Group of answer choices
C-) arr[2][1]
A-) arr[0][3]
D-) arr[2][2]
B-) arr[3][0]
Trending now
This is a popular solution!
Step by step
Solved in 5 steps