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

4. (3) Assume a double vector named v has been declared and filled with values.

ID: 3838632 • Letter: 4

Question

4.         (3) Assume a double vector named v has been declared and filled with values. Assume an iterator to a double vector named iter has been declared. Which code segment correctly traverses the vector displaying each value?

a.         iter = v.begin( );                                                                                              b.         iter = v.begin( );

            while (iter != v.end ( ))                                                                                               while (iter != v.end( ))

            {          cout << *iter << endl; { cout << v[iter] << endl;

            iter++; } iter++;             }                                                         

c.         for (int i = 0; i < v.size ( ); i++)                                              d.         for (iter = 0; iter < v.size( ); iter++)

            cout << iter[i] << endl; cout << *iter << endl;

Explanation / Answer

The answer is option "a"

a.         iter = v.begin( );

            while (iter != v.end ( ))

            {

cout << *iter << endl;

iter++;

}

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