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

Create a function template named \"findLargerValue\", which when given two value

ID: 667563 • Letter: C

Question

Create a function template named "findLargerValue", which when given two values, will return the larger of the two values.

In the main() function, use the "findLargerValue" function to find and display the larger value/object for the following:

Two integer values

Two double values

Two Trip objectsCreate a class called Trip which has:

an integer data element length

an overloaded "operator >" function to compare two Trip objects. For example, if (myTrip > yourTrip) cout<<"myTrip is longer"<<endl;, where myTrip and yourTrip are objects of the Trip class,

Explanation / Answer

#include <iostream>

using namespace std;

class Trip{
public:
   int length;
   Trip(int l){
       length = l;
   }
   bool operator<(Trip &T){
       return length < T.length;
   }
};

template <class T>
T findLargerValue(T one, T two){
   if(one < two){
       return two;
   }
   else{
       return one;
   }
}

int main(){
   int a = 2, b = 3;
   cout << "Larger value is " << findLargerValue(a, b) << endl;
   double c = 2.6, d = 1.5;
   cout << "Larger value is " << findLargerValue(c, d) << endl;
   Trip T1(5), T2(3);
   cout << "Larger value is " << findLargerValue(T1, T2).length << endl;
   return 0;
}

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