For all of these programs, never use using namespace std;
. Declare each function explicitly as necessary.
-
Write a function named
insertionSort
that takes a pointer to an integer and an integer as arguments. The function should sort the array passed to it using the insertion sort algorithm and print out each step of the process. Demonstrate the function in a program. Do the same for selection sort, or any other sorting algorithm that interests you. -
Write a function template named
sum
that takes two different types as arguments. The function returns the sum of the two values passed to it, using the type given by the first value. Demonstrate the template in a program with combinations ofint
anddouble
. -
Write two functions that each take a pointer to an integer, an integer, and a string as arguments. One function,
arrayToFile
, should push the contents of the given array to the given filename. The other function,fileToArray
, pushes the contents of the file to the array. Demonstrate the functions by copying the contents of one array to another array using the filedata.txt
. Make sure to check for errors. -
Write a function named
recursivePower
that takes a double and an integer as arguments. The function should recursively take the double to the power of the integer. Write another function namediterativePower
that does the same thing, but iteratively. Demonstrate the functions in a program.