Ask Question
31 March, 17:57

Write the definitions for three function named max. Each receives two parameters, of the same type, and returns the larger of the two values. Define one of these functions to apply to type double, another to type int and a third to type char.

+2
Answers (1)
  1. 31 March, 21:42
    0
    The method definition to this question can be given as:

    Method definition:

    double max (double x, double y) / /define method with double parameter

    {

    if (x>=y) / /check condition.

    return x; / /return value

    else

    return y; / /return value

    }

    double max (int x, int y) / /define method with integer parameter

    {

    if (x>=y) / /check condition

    return x; / /return value

    else

    return y; / /return value

    }

    double max (char x, char y) / /define method with char parameter

    {

    if (x>=y) / /check condition

    return x; / /return value

    else

    return y; / /return value

    }

    Explanation:

    The above method definition can be described as below:

    In the first method definition first, we define a method that is "max () ". In this method we pass two variables as a parameter that is "x and y" and the datatype of this is double. Then we use a conditional statement. In the if block we check if variable x is greater then equal to y then it will return x else it will return y. In the second method definition, we define a method that is same as the first method name but in this method, we pass two integer variable that is "x and y". Then we use a conditional statement. In the if block we check if variable x is greater then equal to y then it will return x else it will return y. In the third method definition, we define a method that is same as the first and second method name but in this method, we pass two char variable that is "x and y". Then we use a conditional statement. In the if block we check if variable x is greater then equal to y then it will return x else it will return y.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the definitions for three function named max. Each receives two parameters, of the same type, and returns the larger of the two ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers