Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// This program demonstrates the vector member functions. #include <iostream> #i

ID: 3888547 • Letter: #

Question

// This program demonstrates the vector member functions.

#include <iostream>

#include <vector>

using namespace std;

int main()

{

vector<int> values;

// Store values in the vector.

______________________;

______________________;

______________________;

cout << "The size of values is " << _____________ << endl;

// Remove a value from the vector.

cout << "Popping a value from the vector... ";

_________________________

cout << "The size of values is now " << values.size() << endl;

// Now remove another value from the vector.

cout << "Popping a value from the vector... ";

_________________________

cout << "The size of values is now " << values.size() << endl;

// Remove the last value from the vector.

cout << "Popping a value from the vector... ";

_______________________

cout << "The size of values is now " << values.size() << endl;

// Store values in the vector.

______________________;

cout << "I will call the clear member function... ";

values.clear();

cout << "Now, the values vector has "

<< values.size() << " elements. ";

return 0;

}

Explanation / Answer

Please refer below code

I have specified the code by comment "added in code"

#include <iostream>
#include <vector>
using namespace std;

int main()
{
vector<int> values;

// Store values in the vector.
//added in code
for(int i = 0; i < 10; i++)
{
values.push_back(i);
}

cout << "The size of values is " <<values.size()<< endl;

// Remove a value from the vector.
cout << "Popping a value from the vector... ";
values.erase(values.begin()); //added in code

cout << "The size of values is now " << values.size() << endl;

// Now remove another value from the vector.
//removing element from starting index i.e front
cout << "Popping a value from the vector... ";
values.erase(values.begin()); //added in code

cout << "The size of values is now " << values.size() << endl;

// Remove the last value from the vector.
cout << "Popping a value from the vector... ";
values.pop_back(); //added in code
cout << "The size of values is now " << values.size() << endl;
// Store values in the vector.//added in code
for(int i = 60; i < 70; i++)
{
values.push_back(i);
}
cout << "I will call the clear member function... ";
values.clear();
cout << "Now, the values vector has "
<< values.size() << " elements. ";

return 0;
}

Please refer below output

The size of values is 10
Popping a value from the vector...
The size of values is now 9
Popping a value from the vector...
The size of values is now 8
Popping a value from the vector...
The size of values is now 7
I will call the clear member function...
Now, the values vector has 0 elements.

Process returned 0 (0x0) execution time : 0.040 s
Press any key to continue.