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

//Write functions sum and printEvenIndex //Write function title of fun, change,

ID: 3844942 • Letter: #

Question

 //Write functions sum and printEvenIndex //Write function title of fun, change, swapIt. #include <iostream> using namespace std;  int fun(int a[][2], int b[], int c);  void change(int a[], int inc); void swapIt(int &a, int &b); int range(int a[][2], int row, int col){    int sm = a[0][0]; //assume the first element is the smallest and largest    int lg = a[0][0];    for (int r = 0; r < row; r++){       for (int c = 0; c < col; c++){          if (a[r][c] < sm) sm = a[r][c];          else if (a[r][c] > lg) lg = a[r][c];       }    }    return lg - sm; }  int main(){    double arr[6] = {2.3, 4.1, 5.3, 1.3, 6.5, 0.2};    cout << gapSum(arr, 6) << endl;  //prints 18.5    cout << sum(arr[1], arr[4]) << endl;  //prints 10.6      printEvenIndex(arr, 6); //prints out 2.3 5.3 6.5          int x[3][2] = {{1,2},{3,3},{4,5}};    int y[4] = {1,2,3,4};    cout << x[1][0]; // What is the output of this line?    for (int i = 0; i  < 2; i++) cout << x[i][i] << endl; // What's the output?    cout << y[y[1]] << endl; // Output?        y[3] = fun(x, x[0], x[0][0]);    change(y, 2); //doubles all the values in y, y becomes 2 4 6 8    x[0][0] = 0;    swapIt(x[x[0][1]][x[0][0]], y[0]); //exchange the values in y[0] with x[x[0][1]][x[0][0]]    int num_range = range(x, 3, 2);    cout << "The range is " << num_range << endl;    return 0; }  

Explanation / Answer

//No information is given about fun()

// In change function, size of the array is also required


double sum(double a,double b){
return a+b;
}

void printEvenIndex(double arr[], int size){
int i;
for(i=0;i<size;i=i+2)
cout<<arr[i]<<" ";

}

void swapIt(int &a, int &b){
int temp;
temp = a;
a=b;
b=temp;
}

void change(int a[], int inc){
  
int i;
for(i=0;i<4;i++)
a[i] = inc*a[i];

}

int main(){
double arr[6] = {2.3, 4.1, 5.3, 1.3, 6.5, 0.2}; cout << gapSum(arr, 6) << endl; //prints 18.5 cout << sum(arr[1], arr[4]) << endl; //prints 10.6
printEvenIndex(arr, 6); //prints out 2.3 5.3 6.5
int x[3][2] = {{1,2},{3,3},{4,5}};
int y[4] = {1,2,3,4};
cout << x[1][0]; // Prints 3
  
for (int i = 0; i < 2; i++)
cout << x[i][i] << endl; // prints 1,3
cout << y[y[1]] << endl; // prints 3
y[3] = fun(x, x[0], x[0][0]);
change(y, 2); //doubles all the values in y, y becomes 2 4 6 8
x[0][0] = 0; swapIt(x[x[0][1]][x[0][0]], y[0]);
//exchange the values in y[0] with x[x[0][1]][x[0][0]]
int num_range = range(x, 3, 2);
cout << "The range is " << num_range << endl; // prints 4 (5-1)
return 0;
}