Question

12. In C#, without using the Math.Max function, write your own MyMax function that returns the...

12. In C#, without using the Math.Max function, write your own MyMax function that returns the maximum of whatever number of double-valued numbers are passed to it. Also provide a statement illustrating calling the function

Using polymorphism, expand Q#12 to be able to also handle the cases where either the arguments are all int or the values are all decimal

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class MaxNumber {

    public static int MyMax(int n1, int n2) {
        if (n1 > n2)
            return n1;
        else
            return n2;
    }

    public static double MyMax(double n1, double n2) {
        if (n1 > n2)
            return n1;
        else
            return n2;
    }

    public static void Main(string[] args) {
        Console.WriteLine(MyMax(2, 9));
        Console.WriteLine(MyMax(15, 9));

        Console.WriteLine(MyMax(2.5, 1.7));
        Console.WriteLine(MyMax(1.5, 9.5));
    }
}
Add a comment
Know the answer?
Add Answer to:
12. In C#, without using the Math.Max function, write your own MyMax function that returns the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++.Write the body of a function that returns the sum of all elements in a two-dimensional...

    C++.Write the body of a function that returns the sum of all elements in a two-dimensional array passed to it as an argument. Declare and initialize all needed variables. int arraySum(const int numbers[][COLS], int rows) { }

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • Using python, Write a function max3 that takes three numbers as its arguments and returns the...

    Using python, Write a function max3 that takes three numbers as its arguments and returns the greatest of these three numbers. Your submitted file for this problem should include (a) function definition, obviously, and (b) the code that calls that function (for this problem you do not have to package that calling code into the main() function although you may if you want to), so that if I run your *.py file it computes and prints something (e.g. few test...

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • 1. Write a C programme by using visual Studio: a) Write a function with parameters that...

    1. Write a C programme by using visual Studio: a) Write a function with parameters that returen the largest of three integer arguments. So users could call your function (name: max3) to output the maximum of three input values. b) Make a function outside of the main routine. And in the main routine, please call this function and print the harmonic mean. The harmonic mean of two numbers is obtained by taking the inverses of the two numbers, averaging them,...

  • C++ write a function named subtract that takes two integers as parameters and returns the result...

    C++ write a function named subtract that takes two integers as parameters and returns the result of subtracting the second number from the first. i.e. int1 - int2 Change subtract to have default arguments for its two parameters. Pick whatever non-zero numbers you would like. Write a prototype for subtract before main so the program runs without error. I cant figure out the part where you pass no parameters, I've tried to set defailt values for the parameters but it...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • Using C Write a function that takes two ints and returns the minimum (smallest) of those...

    Using C Write a function that takes two ints and returns the minimum (smallest) of those two ints. Include a function prototype. In main, call the function with two int inputs of your choice and print the returned value to the output window. The function should not print, just return the smallest number (int). If the numbers are the same, the minimum is just the number. Please use notes to explain, thanks!

  • Do it in C please, without using parseint, atoi. * The isinteger ) function examines the...

    Do it in C please, without using parseint, atoi. * The isinteger ) function examines the string given as its first argument, and returns true if and only if the string represents a well-formed integer. A well-formed integer consists only of an optional leading - followed by one or more decimal digits. Returns true if the given string represents an integer, false otherwise. bool isinteger (char +str) *The parseint ) function parses a well-formed string representation of * an integer...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT