Answer to Question #128507 in C++ for Ali Rizwan

Question #128507
Write a function that takes two distance values as argument and returns the Large one. Include main ( ) program accepts two distance values from the user , compares them , and display the larger
1
Expert's answer
2020-08-07T14:15:18-0400
#include <iostream>

#include <cstring>




using std::cout;

using std::endl;

using std::cin;

using std::string;




//template function




template<typename T>

T func(T value1,T value2);




int main()

{

  //Call func function for type the int, float, double, char 

  int val1,val2;

  cout<<"Enter the value1 ";

   cin>>val1;

    cout<<"\nEnter the value2 ";

     cin>>val2;

      cout<<"\nlarge value is "<<func(val1,val2)<<endl;

   

  //Call func function for type the string     

  string s1,s2;

  cout<<"Enter the s1 ";

   cin>>s1;

    cout<<"\nEnter the s2 ";

     cin>>s2;

      cout<<"\nlarge value is "<<func(s1,s2)<<endl;

       

return 0;

}




template<typename T>

T func(T value1,T value2)

{

  if(value1>value2)

    return value1;

      else

        return value2;

}

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS