Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help on c++ programming please 1. The function fill_vector assumes that its argument is a vector that already has allocated some space which needs

need help on c++ programming please

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

1. The function fill_vector assumes that its argument is a vector that already has allocated some space which needs to be filled. We can do this by using the push back method provided by the vector class. Look up the push_back routine in the .NFT help database and ask your TA for help if you want more clarification Now in your hcader file implement the void add_numbers (vector &data) method that adds 10 random numbers to the data vector (fcel frec to usc a for loop). Test your code by creating an empty vector in main(), call the add_number function, and then print the vector from main(). Another interesting test you should try is calling add_number twice in a row with the same argument - what happens? [L4.P1] 2 Take a look at the sample print function provided in the VectorDriver, and then create a new function void print_even(const vector& data) that prints all of the elements in the data vector that are stored at an even index (i.e data.at(0), data.at(2), ...) Never hesitate to ask the TA for help if you run into problems! [L4.P2] In the tasks above, we used the at () method to access elements of a vector. There is another way to do it - through the use of an object called an iterator. For now, think of iterators as very sophisticated pointers that can be dereferenced using the * operator, and can be incremented via ++ (plus, plus) and decremented via -- (minus, minus). What we mean by "incrementing" an iterator is that it moves "forward" in a sequence of items stored in a container. For example, if you start 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

10-9 How have social technologies changed e-commerce?

Answered: 1 week ago