Solved–Lab #2 –Solution

$30.00 $19.00

Objectives: 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…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

5/5 – (2 votes)

Objectives:

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.

lab02.cpp

lab02.exe

Grading:

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.