Assignment 3

Create a project called TemplateOverLoading and add it to your workspace. Create an implementation file called main and add to TemplateOverloading.  Create two template functions named Max. The first template function Max should accept any three values of type primitive (ei. double, float, char). The second template function should accept three arrays of the same type and length and compare them to determine which one is greater than the other based on value comparison. Use the following main function to test your code.

 Solution

//------------------------------ Begin Main -------------------------------------
int
main()
{
    int i=10, j = 12, k =-101;
    cout << "Max(i,j,k): " << Max(i, j, k) << " sould equal " << 12 << endl;

    double di=10.3, dj = -12.4, dk =101.10;
    cout << "Max(di, dj, dk): " << Max(di, dj, dk) << " sould equal " << 101.10 << endl;

 
    char ch1='a', ch2='m', ch3='z';
    cout << "Max(ch1, ch2, ch3): " << Max(ch1,ch2,ch3) << " sould equal " << 'z' << endl;

    int intArr01[5] = { 1, 2, 3, 4, 5 };
    int intArr02[5] = { 1, 2, 3, -4, 5 };
    int intArr03[5] = { 1, 2, 3, 4, -5 };

    cout << "Max(intArr01, intArr02, intArr03, 5): ";
    cout << Max(intArr01, intArr02, intArr03, 5);
    cout << " should be " << intArr01 << endl;

    char charArr01[6] = { 'a', 'b', 'c', 'd', 'e', 0x00 };
    char charArr02[6] = { 'z', 'y', 'x', 'w', 'v', 0x00 };
    char charArr03[6] = { 'a', 'b', 'd', 'm',  'l', 0x00 };

    cout << "Max(charArr01, charArr02, charArr03, 6): ";
    cout << (char*)Max(charArr01, charArr02, charArr03, 6) << endl;
    cout << "  should be " << (char*)charArr02 << endl;

    return 0;
}

//------------------------------- End File ---------------------------------------