Can anyone please help me with this question??????
Create two vectors. Fill both vectors with 100 random integers in the range [-1000, +1000],in random order. After that, do the following:
a) Create a third vector, which contains the sums of the integers in the same positions as in the two vectors created earlier.
b) Print out the number of positive integers and the number of negative integers in the third
vector
The code is not complete yet what I have done is only for the first part but I'm not sure whether the random values is stored in the vector1 and vector2 or not. For the adding part I'm not sure how to do it.
which one is it?
just try and get one vector populating with values to begin with. you might be better off declaring like this: vector <int> vector1;
and then using push_back 100 times in your for loop.
e.g.
1 2 3 4 5 6 7 8 9
vector <int> vector1;
constint numElements = 100;
for(int i=0;i<numElements;i++)
{
randomNum = // generate your number
vector1.push_back(randomNum);
}
Thanks for the help on storing the random values in my vector. Now I need to calculate the sum of my vector1 and vector2 according to their positions or index number???
vector <int> vector1;
constint numElements = 100;
int sum = 0;for(int i=0;i<numElements;i++)
{
randomNum = // generate your number
sum+=randomNum;
vector1.push_back(randomNum);
}
// outside of this loop 'sum' will give you the total sum.
Can anyone help me on how to Delete all the contents of the third vector. Replace its content with the content of the first vector, and then continue (add at the back) with the content of the second vector.
I know how to delete the content in the third vector but I don't know how to replace it with the value of vector 1 and vector 2 together in vector 3. Should I use the assign function but still I don't know how to put vector 1 and vector 2 value in vector 3. Can anyone please help me??