Question: #Given the integer vector myValues with four elements and the input integer numNew, resize myValues to add numNew elements to the vector. After resizing myValues,

#Given the integer vector myValues with four elements and the input integer numNew, resize myValues to add numNew elements to the vector.
After resizing myValues, the new elements are initialized with the default value 0.
Ex: If the input is 2, then the output is:
9768
976800
Note: Assume that numNew is a non-negative integer.include
#include
using namespace std;
int main(){
vector myValues(4);
int myValuesSize = myValues.size();
int numNew;
int i;
myValues.at(0)=9;
myValues.at(1)=7;
myValues.at(2)=6;
myValues.at(3)=8;
cin >> numNew;
for (i =0; i < myValues.size(); ++i){
cout << myValues.at(i)<<"";
}
cout << endl;
/* Your code goes here */
for (i =4; i < numNew + myValuesSize; ++i){
myValues.at(i)=0;
}
for (i =0; i < myValues.size(); ++i){
cout << myValues.at(i)<<"";
}
cout << endl;
return 0;
}Given the integer vector myValues with four elements and the input integer numNew, resize myValues to add numNew elements to the vector.
After resizing myValues, the new elements are initialized with the default value 0.
Ex: If the input is 2, then the output is:
9768
976800
Note: Assume that numNew is a non-negative integer.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!