Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 main.cpp In main.cpp do the following step by step: 1. Globally define array a [] of integers consisting of values: 5, 7,-2, 8, 11,

image text in transcribed

image text in transcribed

1 main.cpp In main.cpp do the following step by step: 1. Globally define array a [] of integers consisting of values: 5, 7,-2, 8, 11, -9,4,6, 12, and -1 in order. 2. Globally define a vector of integers, without initial values. Call it veci. 3. Define the following functions on vectors. In all of the following functions pass the vector by refer- ence. In addition, you must use range-based for loops for all required iterations overs vectors. (a) Define function void initVector(...) that receives a vector of integers as its first input, an array of integers as a second input, and an integer as its third input. The third input represents the number of elements in the input array. Initialize the input vector with the elements existing in the input array (3 points). (b) Define function void print Vector (...) that receives a vector of integers as input and prints the elements residing within that vector in the standard output. Since the input vector is not being modified by this function, define it to be constant (3 points). (c) Define function int minVector (...) that receives a vector of integers as input and re- tums the least element. Since the input vector is not being modified by this function, define it to be constant (3 points). (d) Define function int product Vector(...) that receives a vector of integers as input and retums the product of all elements within the input vector. Since the input vector is not being modified by this function, define it to be constant (3 points). (e) Define function void doubleVector (...) that receives a vector of integers as input and doubles every element in that vector. Note that the vector is being modified by this function (3 points) (f) Define function void aggregationVector (...) that receives a vector of integers as input and computes an aggregated vector defined as follows: First element of the aggregated vector is the same as the first element of the input vector. Second element of the aggregated vector is the summation of the first two elements of the input vector. Third element of the aggregated vector is the summation of the first three elements of the input vector. Note that the vector is being modified by this function (4 points). In main() function do the following step by step, using the functions defined above: (i) Initialize veci according to array a [] using the function defined above (1 points). (ii) Print out the elements of veci, using to the function defined above (1 points). (iii) Print out the minimum element of vecl using the functions defined above (1 points). (iv) Print out the product of all elements of vecl using the functions defined above (1 points). (v) Print out the updated vecl after doubling each element (using the function defined above) (1 points). (vi) Print out the updated vecl after aggregating its element values (using the function defined above) (1 points). The output of the program may look like the following: vecl content: 5, 7, -2, 8, 11, -9, 4, 6, 12, -1 minimum of veci: -9 product of vecl: -15966720 doubling each element of vecl: 10, 14, -4, 16, 22, -18, 8, 12, 24, -2 aggregating element values in vecl: 10, 24, 20, 36, 58, 40, 48, 60, 84, 82

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

Students also viewed these Databases questions

Question

If you were forced to give up one sense, which would it be? Why?

Answered: 1 week ago