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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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<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]

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education