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

Resize vector countDown to have newSize elements. Populate the vector with integ

ID: 3766748 • Letter: R

Question

Resize vector countDown to have newSize elements. Populate the vector with integers {newSize, newSize - 1, ..., 1}. Ex: If newSize = 3, then countDown = {3, 2, 1}, and the sample program outputs: 3 2 1 Go!

Code given:

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

int main() {
vector<int> countDown(0);
int newSize = 0;
int i = 0;

newSize = 3;

/* Your solution goes here */

for (i = 0; i < newSize; ++i) {
cout << countDown.at(i) << " ";
}
cout << "Go!" << endl;

return 0;
}

Anything bolded cannot be edited. Please bold your inputed code to diffrentiate it from the rest.

Explanation / Answer

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

int main() {
   vector<int> countDown(0);
   int newSize = 0;
   int i = 0;

   newSize = 3;

   /* Your solution goes here */

   for(int i=newSize;i>=1;i--)
        countDown.push_back(i);
       
   for (i = 0; i < newSize; ++i) {
      cout << countDown.at(i) << " ";
   }
   cout << "Go!" << endl;

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote