1) Write a function void sort (double* p, double* q)
That receives two pointers and sorts the values to which they point. So, if you call
sort(&x, &y)
then after the call x is smaller or equal than y. Include the function in a program with the
following main() to test the function:
int main(){
double x = 500;
double y = 22;
sort (&x, &y);
cout << "x = " << x << " y = " << y; //should print 22 then 500
}
2) Write a function that returns a pointer to the maximum value of an array of floating-
point data: double* maximum (double* a, int size)
Include it in a program with the following main() to test the function.:
int main(){
double data[] = { 1, -4, 35, 9, 26 };
double* max = maximum(data, 5);
cout << *max << endl; // should print 35
for (int i=0; i<5; i++)
cout << data[i] << " "; // array should remain unchanged
}
3) Write a function int * getdata (int & size)
that asks the user for a size and a number of data, creates a dynamic array of that size,
containing that data, and returns the dynamic array. Test the function with the following
main ():
int main(){
int size;
int * p = getdata (size);
for (int i=0; i<size; i++) {
cout << p[i] << " ";
}
}