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

Arrays and Functions For this assignment, you\'ll be writing two functions. Belo

ID: 3678873 • Letter: A

Question

Arrays and Functions For this assignment, you'll be writing two functions. Below are the C++ signatures for the functions., as well as a brief explanation of each. void arprt (int arr[], int size, int perln) - Given the array arr having the given size, display the values in the array. A newline should only be output for every perln values displayed, and following the last value. Values displayed on the same line should be separated by a space. In other words, output the values in the array, perln values per line of output. int expos (int arr[], int size, int dest[])- Given the array arr having the givern size, and an array dest that is at least as large as arr, copy from the arr array into the dest array only those values in arr that are greater than zero. Return the number of values that were copied into dest. Your functions are expected to adhere to the standard MIPS conventions for parameter passing, returning values, and protecting registers used in the function. Your main program will call upon these functions to process four arrays. These arrays will be defined as follows data .align 2 .eqv size1,9 .word nums1: 12,-13, 25, 66,102, -111, -234,53, 26 .eqv size2,12 .word nums2 44, 55, 22, -33,44, -77,77,44,33,99,21, -99 .eqv size3,6 .word nums3: pos: Your main program will mainly just make function calls, as follows (shown in C++) 21, -32, -44, -112, -43, -99 .space 48 int nsize; cout

Explanation / Answer

void arprt(int arr[], int size, int perln){
int i = 0;

while (i != size){
cout << arr[i] << ' ';
i++;
if (i % perln == 0)
cout << endl;
}
}

int expos(int arr[], int size, int dest[]){
int i = 0, j = 0;
while (i != size){
if (arr[i] > 0){
dest[j] = arr[i];
j++;
}
i++;
}
return j;
}

The default behavior in C++ when returning an array is that the program actually returns a pointer to the first index in the array, so what you need to do is change your function header so it returns an int pointer instead of an int. Additionally, you'll also likely have to change your function call so the returned pointer is stored in an appropriate variable. What you're trying to do by returning an array by value is not done in C++.

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