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

(C++) Write a function that takes as input parameters (using call by pointer) 3

ID: 3869943 • Letter: #

Question

(C++)

Write a function that takes as input parameters (using call by pointer) 3 integers. It generates a random number between 25 and 50 (not including 50). It then creates an array on the memory heap of that length. It generates a random high number (mine was between 5 and 10) and a random low number (between -5 and -10) and fills in the array iteratively with random numbers between the high and the low numbers*, and it returns that array. The input parameters should be modified so that it holds the length of the array, the high value, and the low value.

*not including the high in general when we specify a range, we include the first value but not the last. If I forget to say that in the future, you can assume that’s what I intended.

Explanation / Answer

#include <bits/stdc++.h>

using namespace std;

int array[3],b,c,d;

void enter(int *array)
{
int i;
for(i=0;i<3;i++)
{
cin>>array[i];

}

}
int main()
{
int k[3];
enter(k);
b = 25+(rand()%49-25+1) ;
cout<<b<<endl;
int array2[b];
int i=0;
while( i<b)
{
array2[i] = 5+(rand()%10-5+1);
// cout<<array2[i]<<" ";
i++;
array2[i] = -10+(5+(rand()%10-5+1));
// cout<<array2[i]<<endl;
i++;
}
sort(array2,array2+b);
array[0] = b;
cout<<"maximum element"<<endl;
array[1] = array2[b-1];
cout<<"minimum element"<<endl;
array[2] = array2[0];
for(i=0;i<3;i++)
{

cout<<array[i]<<" ";
}
return 0;
}