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

What is going on in these programs? Please utilize C++ to extrapolate the proces

ID: 3626545 • Letter: W

Question

What is going on in these programs? Please utilize C++ to extrapolate the process behind each important part(do the parts that are in bold red font).

#16 void remove_min_max(vector& v))  // **EXAMPLE the purpose of void and &v is....
{
double max=v[0],min=v[0];
int ma,mi;
for (int i=1; i {
if(v[i]>max){ max = v[i];ma = i; }
if(v[i]
}
v.erase(v[ma]);
v.erase(v[mi]);
}

___________________________
#8 #include
#include
using namespace std;
void swap_values(vector& v)
{
int k=v.size()/2;
for(int i=0; i{
int temp = v[i];
v[i]=v[k];
v[k]=temp;
k++;
}
}
int main()
{
int a[]={4, 8, 2, 9, 1, 7, 6, 3};
vector v(a,a+sizeof(a)/sizeof(int));
cout << "before swap"<for(int i=0; icout << v[i]<<" ";
swap_values(v);
cout << " after swap"<for(int i=0; icout << v[i]<<" ";

return 0;
}

____________________

Explanation / Answer

please rate - thanks

hope this is ok

the cramster editor mutilated the code so I'm guessing at some of it

void remove_min_max(vector& v)) //returns nothing and accepts a vector that can be changed.
{
double max=v[0],min=v[0]; //set smallest and largest numbers to 1st value in the vector
int ma,mi;
for (int i=1; i {          //go through each element of the vector
if(v[i]>max){ max = v[i];ma = i; } //if it's larger then the current largest
                                    //save it's index and make it the largest
if(v[i]                             //if it's smaller then the current smallest
}                                    //save it's index and make it the smallest
v.erase(v[ma]);                     //remove the largest element from the vector
v.erase(v[mi]);                     //remove the smallest element from the vector
}

___________________________
#include
#include
using namespace std;
void swap_values(vector& v)        //returns nothing and accepts a vector that can be changed.
{
int k=v.size()/2;                  //k is the number of elements in the vector divided by 2 (center element)
for(int i=0; i{                   
int temp = v[i];                   //swap element i in the vector with element k in the vector
v[i]=v[k];
v[k]=temp;
k++;                                 //go to next element in 2nd half
}
}
int main()
{
int a[]={4, 8, 2, 9, 1, 7, 6, 3};
vector v(a,a+sizeof(a)/sizeof(int));   //create a vector with the elements in array a
cout << "before swap"<for(int i=0; icout << v[i]<<" ";   //print the vector
swap_values(v);                             //swap it's values   appears to be swap first half with 2nd half of vector
cout << " after swap"<for(int i=0; icout << v[i]<<" "; //print the vector

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