Make a template out of the following file and test on different data types, incl
ID: 3777464 • Letter: M
Question
Make a template out of the following file and test on different data types, including int, double and string.
#include <iostream>
#include <string>
using namespace std;
//Make a template out of the prototype
int myMax(int one, int two);
int main()
{
int i_one = 3, i_two = 5;
cout << "The max of " << i_one << " and " << i_two << " is "
<< myMax(i_one, i_two) << endl;
//Test your template on float and string types
return 0;
}
//Make a template out of this function. Don't forget the return type.
int myMax(int one, int two)
{
int bigger;
if (one < two)
{
bigger = two;
}
else
{
bigger = one;
}
return bigger;
}
Explanation / Answer
#include <iostream.h>
#include <conio.h>
template <class T>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.