Exercise 1 - Function Templating For this part of the lab make a template out of the myMax function and test it on different data types Start with the repl code provided to you. Compile and run the program to see how it works. Make a template out of myMax. Don't forget the return type. . Modify the prototype appropriately. Test your myMax template on int, double, and string types. When you are done your output should resemble this: The max of ) and 5 13 5 The max of 5.6 and 7.3 is 7.3 The max of donkey and apple is donkey Exercise 2 - Class Templating For this part of the lab you will make a template out of the Matrix class, test it on different data types, and add a generic sort member function. Part 1: Setup Start with the repl code provided to you. Add the template types to matrix.cpp Template the definition of the Matrix class in matrix.h. Template the member functions in matrix.cpp. The Makefile is set up for you. Use it to compile and run the program to make sure everything is working. Part 2: Extend Add two more 2D arrays to tempMain.cpp that hold a new data type. Create an instances of Matrix that can hold that data type and use the templated demo Template function to show that your templated class works Test your changes. Your completed exercise should resemble this: Demonstrating with string matrix: Matrix set to first array don ta Matrix incremented by second array Congratulations you are the Demonstrating with int matrix: Matrix set to first array 123 ar Congray lain almost done Lab 17 7 7 batrix incremented by second array 7 7 7 Demonstrating with float matrixt Matrix set to first array 1.6 2.5 3.4 4.3 5.2 6.1 Matrix incremented by second array 7.7 7.7 7.7 7.7 7.7 7.7 const int MAXROWS=2; const int MAXCOLS=3; class Matrix { private: int doubleArray[MAXROWS] [MAXCOLS]; int rows; int cols; public: //Constructor Matrix(); //Set rows to MAXROWS and cols to MAXCOLS //Initialize all the values of doubleArray to zero //Getter Functions void printMatrix(); // Setter Functions void setMatrix (int [] [MAXCOLS]); //set the doubleArray to what is sent void addMatrix(int [][MAXCOLS]); //add an array to doubleArray void addMatrix(Matrix other Matrix); l/No destructor needed // Filename: maxTemplate.cpp // Purpose: Demonstrate the use of function templates. #include
#include using namespace std; l/Make a template out of the prototype int myMax (int one, int two); int main() { int i_one = 3, i_two = 5; cout using namespace std; Matrix::Matrix() { rows = MAXROWS; cols = MAXCOLS; for (int i=0; i #include #include "matrix.h" using namespace std; template void demoTemplate(Matrix& M, T1 array1[][MAXCOLS], T1 array( [MAXCOLS]); int main() { string str1[MAXROWS] [MAXCOLS] = { {"Congra", "y", "ar"}, {"alm", "don", "La"} string str2[MAXROWS][MAXCOLS] = { {"tulations", "ou", "e"}, {"ost", "e the", "b!"} }; int nums1[MAXROWS][MAXCOLS] = { {1,2,3}, {4,5,6} int nums2[MAXROWS][MAXCOLS] = { {6,5,4}, {3,2,1} }; Matrix stringMatrix; Matrix intMatrix; cout stringMatrix; Matrix intMatrix; cout void demoTemplate(Matrix&M, T1 array10[MAXCOLS]. T1 array2[] [MAXCOLS]) { M.setMatrix(array1); cout