Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

<p><span style=\"font-family: Arial;\"><span style=\"font-family: Arial;\"> <p><

ID: 3626484 • Letter: #

Question

<p><span><span>
<p><span>*Please utilize C++ format when answering questions</span></p>
<span><span><span><font face="Arial">
<p><span>43. </span></p>
</font></span></span><span><span>a) Write a function that passes in a vector of integers and returns, using 2 integer parameter</span></span></span></span></span><span>
<p>
<p>
<p>variables, the sum of all of the even values in the vector and the sum of all of the odd values</p>
<p>in the vector. For example, if the function is passed a vector with the values,</p>
<p>2, 5, 8, 10, 11, 4, then the sum of all even values would be 24 (2 + 8 + 10 + 4) and the sum of</p>
<p>all odd values would be 16 (5 + 11).</p>
<p>b) Write a main function that tests this function at least once. For the vector, you may</p>
<p>initialize it with any values you choose, but you must give it at least 2 values.</p>
</p>
</p>
</span></p>

Explanation / Answer

#include<iostream>
#include<vector>
using namespace std;
void sumevodd(vector<int>& v,int& even,int& odd)
{
for(int i=0; i<v.size(); i++)
{
if(v[i]%2==0) even = even+v[i];
else odd = odd+v[i];
}
}
int main()
{
int a[] = {2, 5, 8, 10, 11, 4};
vector<int> v(a,a+sizeof(a)/sizeof(int));
int even=0,odd=0;
sumevodd(v,even,odd);
cout<<"sum of even values is "<<even<<endl;
cout<<"sum of odd values is "<<odd<<endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote