Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this lab assignment, you will be implementing some simple functions which make use of vectors . Write a C++ program that will implement and

For this lab assignment, you will be implementing some simple functions which make use of vectors. Write a C++ program that will implement and test the two functions described below:

  • First, implement a function called part_one() which reads twenty integer values (entered by the user at the keyboard) into two ten-element vectors, and then iterates through both vectors, one element at a time, adding and multiplying the corresponding values together (that is, add and multiply the first elements in each vector, then the second elements, then the third, etc). The function should add the sums to a third ten-element vector, and the products to a fourth ten-element vector. Finally, it should print all the values in all four vectors, each vector on a single line, with the values separated by commas. Perform these calculations and iterate through the vectors manually using for loops; do not use iterators or other library functions or algorithms which have not (yet) been discussed in class.

  • Next, implement a function called part_two() which reads ten integer values (entered by the user at the keyboard) into a vector, then prompts the user to specify how many times it should right rotate the vector elements in a cyclical fashionthat is, move all the elements one position forward in the vector, and move the last vector element back to the first position. The function should then perform the given number of rotations and output the resulting rotated vector. For example, if the vector elements are ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ... and the number of rotations is given as 3, then the vector should look like this ... 8, 9, 10, 1, 2, 3, 4, 5, 6, 7 ... after the rotation. Again, you should perform this rotation by manipulating the vector elements manually, without using iterators or other library functions or algorithms which have not (yet) been discussed in class. Take care not to "drop" or overwrite any elements in the process! (Hint: you should design an algorithm which rotates the elements once, and then repeat this algorithm inside a for-loop according to the number of rotations requested by the user. You should perform the rotation by copying the elements one at a time from their original positions into their new positions.)

Remember, both of these routines should be implemented as functions! The main() function in your program should contain no more than two lines of code: one call to each of the functions described above. (After you complete the first function and are working on the second, you should temporarily disable or remove the call to the first function, so that you can test the second function in isolation.) These functions do not need to accept any arguments or return any values (since they will print their output to the screen), so they should both use an empty argument list and a return type of void.

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

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago