Answer to Question #243628 in C++ for Jay

Question #243628

Write a function template named maximum() that returns the maximum value of three arguments that are passed to function when it is called. Assume that all three arguments will be of the same data type.

1
Expert's answer
2021-09-28T07:25:23-0400
#include<iostream>
using namespace std;
template <typename P>
P maximum(P first, P second, P third){
	P max = first;
	if(second>first && second > third){
		max = second;
	}
	else if(third > first && third > second){
		max = third;
	}
	return max;
}


int main(){
	cout<<maximum(8,2,20)<<endl; //Testing integer values
		cout<<maximum(1.90892,0.76454,0.20)<<endl; //Testing float values
	cout<<maximum('C','D','A')<<endl; //Testing character values
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Jay
28.09.21, 15:32

Thank you so much

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS