Welcome to the section 7 challenge.
The purpose of this challenge is not to solve a specific problem
but to give you a chance to practice with vectors.
We'll declare two vectors,
and we'll add these vectors to a two-dimensional vector that we'll declare as well.
You'll get a chance to work with the vectors at,
pushback and size methods.
And you'll also work with a two-dimensional vector.
Then at the end of this challenge, I'll ask you to modify a vector element
and analyze the effect it has. You might be surprised by the result.
Please go through the challenge in order and implement each of the directives in the challenge.
Let's go over the details of this challenge together.
First, I'd like you to declare two empty vectors of integers named vector1
and vector2, respectively.
Then add 10 and 20 to vector1 dynamically, using the pushback method.
Display those two vector elements,
using the at method as well as the size using the size method.
Do the same thing for vector2, except we're going to add
100 and 200 this time.
Then I want you to declare an empty two-dimensional vector called vector2d.
Remember, a two-dimensional vector is a vector of vectors.
Then I want you to add vector1 to vector2d using pushback,
then add vector2 to vector2d using pushback as well.
Then display the elements in vector2d using the at method.
Now comes the interesting part. I want you to change
vector1's first element, using the at0 method.
And I want you to change it to a 1000.
Then i want you to display the elements in the 2d vector
again using the at method, just like you did before.
And then finally, display the elements in vector1.
Take a look at the results and see if it's what you expected,
and see what you think happened.
That's it. Good luck, have fun. Once you finish the challenge, extend it any way you wish.
Remember, the more you practice, the easier programming becomes.
Once you finish the challenge, join me in the next video, and we'll go over my solution.