Module 6 Lab - Vectors

 Objective

 

Sample Run:

Enter a list of integers, one at a time. Enter -1 to stop. Enter an integer: 5 Enter an integer: 7 Enter an integer: 9 Enter an integer: -1 The contents of the vector are: 5 7 9 Enter a value to search for: 7 7 was found at position 1. Enter a position to remove (0 to 2): 2 After removing the value, the contents of the vector are: 5 7 Enter a value to insert: 4 Enter a position to insert (0 to 2): 1 After inserting the value, the contents of the vector are: 5 4 7

Tips

  • Use a while loop to prompt the user to input integers until they are finished.

  • Use the push_back function to add integers to the vector.

  • Use a for loop to iterate through the vector and display its contents.

  • Use the find function to search for a value in the vector.

  • Use the erase function to remove an element at a specific position.

  • Use the insert function to insert a value at a specific position in the vector.

Deliverable

Upload the following:

  1. Full source code (.cpp file or .txt file)

  2. Screenshot of the Console with the code executing

COSC-1336 / ITSE-1302 Computer Science - Author: Dr. Kevin Roark