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

Trying to do this in C++ Question 3: Implement following functions: a. void reve

ID: 3590444 • Letter: T

Question

Trying to do this in C++

Question 3: Implement following functions: a. void reverseArray(int arr[], int arrSize) That takes arr, an array of integers, and its size, arrSize. When called, it reorders the elements of the array to appear in a reverse order. For example, if arr is an array containing [1, 2, 3, 4], after calling reverseArray, arr will look like: [4, 3, 2, 1]. b. void removeOdd (int arr[, int& arrSize) That takes arr, an array of integers, and its size, arrSize. When called, the function alters arr so that the only numbers in it at the end are the even ones, which should remain in their original relative order. Additionally, the function updates arrSize so it contains the new logical size of the array after removing the odd numbers (note that arrSize is a parameter used both for input and output) For example, if arr is an array containing [1, 2, 3, 4], after calling removeOdd, arr will look like: [2, 4], and the parameter arrSize will update to 2. Notice the values in arr [2] and arr[3] are discarded. c. void splitParity (int arr[], int arrSize) That takes arr, an array of integers, and its size, arrSize. When called, the function changes the order of numbers in arr so that all the odd numbers will appear first, and all the even numbers will appear last. Note that the inner order of the odd numbers and the inner order of the even numbers don't matter. For example, if arr is an array containing [1, 2, 3, 41, after calling splitParity, arr could look like: [3, 1, 2, 4]

Explanation / Answer

Program in C ;

#include<stdio.h>
#include<conio.h>
#include<iostream.h>


void reverseArray(int arr1[],int size);
void removeOdd(int arr2[],int size);
void splitParity(int arr3[],int size);


void printArray(int arr[],int arrSize);

int main()
{
clrscr();
int arr1[10] = {9,2,14,12,-3};
int arr1Size = 5;

int arr2[10] = {21,12,6,7,14};
int arr2Size = 5;

int arr3[10] = {3,6,4,1,12};
int arr3Size = 5;

reverseArray(arr1,arr1Size);
printArray(arr1,arr1Size);

removeOdd(arr2,arr2Size);
printArray(arr2,arr2Size);

splitParity(arr3,arr3Size);
printArray(arr3,arr3Size);
getch();
return 0;
}

void reverseArray(int arr1[],int arr1Size)
{
int x,i,j=arr1Size;
for(i=0;i<=(arr1Size/2);i++)
{
x = arr1[i];
arr1[i] = arr1[j];
arr1[j] = x;
j--;
}

}

void removeOdd(int arr2[],int arr2Size)
{
int i,j,z=1;
for(i=0;i<=arr2Size;i++)
{
if(arr2[i]%2!=0)
{
arr2[i]=arr2[i+z];
z++;
arr2Size -=z;
}
}
}

void splitParity(int arr3[],int arr3Size)
{
int i,j=0,x,y;

for(i=0;i<=arr3Size;i++)
{
if(arr3[i] % 2!=0)
{
x = arr3[i] ;
arr3[i] = arr3[j];
arr3[j] = x;
j++;
}

}

}

void printArray(int arr[],int arrSize)
{
int i;
for(i=0;i<=arrSize;i++)
{
cout<<arr[i]<<' ';
}
cout<<endl;
}