Westonci.ca is the premier destination for reliable answers to your questions, provided by a community of experts. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.

write a generic function that finds the largest among the three values. your function should have three parameters of the same type. test the function with int, double, and string values.

Sagot :

Functions that have one or more generic type parameters are referred to as generic functions.

How to write a generic function finds largest among the three values ?

Functions that have one or more generic type parameters are referred to as generic functions. They could be standalone functions or methods in a class or struct. A single generic declaration essentially declares a family of functions, with the sole difference being the actual type parameter's substitution with a different one.

#include <iostream>

using namespace std;

int main() {

      double n1, n2, n3;

cout << "Enter three numbers: ";

   cin >> n1 >> n2 >> n3;

    check if n1 is the largest number

   if(n1 >= n2 && n1 >= n3)

       cout << "Largest number: " << n1;

   check if n2 is the largest number

   else if(n2 >= n1 && n2 >= n3)

       cout << "Largest number: " << n2;

   

    if neither n1 nor n2 are the largest, n3 is the largest

   else

       cout << "Largest number: " << n3;

   return 0;

}

Output

Enter three numbers: 2.3 ,8.3 ,-4.2

Largest number: 8.3

To learn more about generic function refer to :

https://brainly.com/question/24304189

#SPJ1