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

C++ PLEASE Write templates for the two functions minimum and maximum. The minimu

ID: 3840973 • Letter: C

Question

C++ PLEASE

Write templates for the two functions minimum and maximum. The minimum function should accept two arguments and return the value of the argument that is the lesser of the two. The maximum function should accept two arguments and return the value of the argument that is the greater of the two.

Test your functions in a main program that propmts the user to choose what type of data they would like to compare (ints , doubles , or strings ). Then, it should ask the user to enter two arguments , as well as whether they would like to know the minimum or the maximum. Then, it should print the minimum or maximum of the two arguments .

Thank you :)

Explanation / Answer

#include <iostream>

using namespace std;

template <class T1>

T1 minelement (T1 first , T1 last)

{

if(first<last)

{

return last;

}

else

{

return first;

}

}

template <class T2>

T2 maxelement (T2 first , T2 last)

{

if(first<last)   

{

return last;

}

else

{

return first;

}

}

int main ()

{

cout <<"Smallest is : " << minelement(33, 43);

cout <<"Max is : " << maxelement(39, 29);

cout <<"Smallest is : " << minelement(33.39, 43.2);

cout <<"Max is : " << maxelement(39.2, 29.3);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote