Lab #2 Solution



The objective of this lab is to help you better understand how to use arrays and vectors in your C++ programs.

After completing this lab, you should be able to:
Explain the differences between an array and a vector, and describe when best to use each.
Discuss some of the errors that can result from poor programming with arrays
Write programs that use vectors and arrays.

Construct a program that does the following:

Declares a vector of doubles.
Declares an array big enough to hold 5 doubles.
Write a loop that prompts the user to enter in a decimal value, and uses the push_back function to add each number to the vector. Get and save 5 values.
Write a loop that copies each element of the vector into the array.
Write a function that sums the elements in the array. Pass the array as a parameter to the function.
Print the sum accurate to 2 decimal places.

After you are satisfied that your program works correctly, place the following files in a zip folder and submit it to Canvas as Lab #2.


o All source code files contain a complete file prologue
o Source code files contain declaration that you did not copy code
o Project has been properly submitted to Canvas
o Code meets style guidelines
o The program works correctly.

error: Content is protected !!