Question

In: Computer Science

DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods...

DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods as follows: Method max (int x, int y, int z) returns the maximum value of three integer values. Method min (int X, int y, int z) returns the minimum value of three integer values. Method average (int x, int y, int z) returns the average of three integer values. In the main method, test all three methods with different input value read from the user. Document your code and properly label the input prompts and the outputs as shown below. Sample run 1: You entered: 20, 8, 12 Max value: 20 Min value: 8 Average value: 13 Sample run 2: You entered: 1, 2, 3 Max value: 3 Min value: 1 Average value: 2 Sample run 3: You entered: 10, 5, 25 Max value: 25 Min value: 5 Average value: 13

Solutions

Expert Solution

using System;

public class MinMaxAvg
{
    static int min(int x, int y, int z)
    {
        int value = x;
        if (y < value)
        {
            value = y;
        }
        if (z < value)
        {
            value = z;
        }
        return value;
    }
    
    static int max(int x, int y, int z)
    {
        int value = x;
        if (y > value)
        {
            value = y;
        }
        if (z > value)
        {
            value = z;
        }
        return value;
    }

    static int average(int x, int y, int z)
    {
        return (x + y + z) / 3;
    }
    
    public static void Main(string[] args)
    {
        Console.Write("Enter first number: ");
        int n1 = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter second number: ");
        int n2 = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter third number: ");
        int n3 = Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("You entered:    " + n1 + ", " + n2 + ", " + n3);
        Console.WriteLine("Max value:      " + max(n1, n2, n3));
        Console.WriteLine("Min value:      " + min(n1, n2, n3));
        Console.WriteLine("Average value:  " + average(n1, n2, n3));
    }
}


Related Solutions

USING C# Design and implement a program (name it SumValue) that reads three integers (say X,...
USING C# Design and implement a program (name it SumValue) that reads three integers (say X, Y, and Z) and prints out their values on separate lines with proper labels, followed by their average with proper label. Comment your code properly.Format the outputs following the sample runs below. Sample run 1: X = 7 Y = 8 Z = 10 Average = 8.333333333333334
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of...
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below.
IN C++ LANGUAGE PLEASE::: Design and implement a program (name it Rectangle) to calculate and display...
IN C++ LANGUAGE PLEASE::: Design and implement a program (name it Rectangle) to calculate and display the area and perimeter of a rectangle with width = 4 and height = 8.
PLEASE DO THIS IN C#Design and implement a programming (name it NextMeeting) to determine the day...
PLEASE DO THIS IN C#Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample runs below. Sample run...
Design and implement a C++ program that performs the following steps:Ask the user to enter a...
Design and implement a C++ program that performs the following steps:Ask the user to enter a positive integer number N; Your program may need to prompt the user to enter many times until it reads in a positive number;Let user to enter N (obtained in the previous step) floating point numbers, and count how many positive ones there are in the sequence and sum up these positive numbers; (Hint: negative numbers or 0 are ignored).Display result.You can and should use...
Design and implement a C++ program read in a whole line of characters as the input...
Design and implement a C++ program read in a whole line of characters as the input string; count and display how many times how frequently (among the letters) each (case insensitive) letter appears in the above mentioned input string; Sample program execution: An example of executing such a program is shown below. Note that the user input is in italic font. Please enter a line of characters: This is a really long line of characters! There are 41 characters in...
Design and implement a C++ program with functions to calculate the pre-tax charge: If the customer...
Design and implement a C++ program with functions to calculate the pre-tax charge: If the customer subscribes to a phone plan called Plan200, then he is charged $5 for the first 200 minutes. For each additional minutes, the customer will be charged $0.10. If the customer subscribes to a phone plan called Max20, then he is charged $0.05 for each minute up to $20. (I.e., the customer never needs to pay more than $20.) If the customer is not subscribed...
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values...
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document your code and properly label the input prompts and the...
: Design and implement class Radio to represent a radio object. The class defines the following...
: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio on or off. Set to...
IN C++ PLEASE!!! Design and implement a programming (name it SimpleMath) that reads two floating-point numbers...
IN C++ PLEASE!!! Design and implement a programming (name it SimpleMath) that reads two floating-point numbers (say R and T) and prints out their values, sum, difference, and product on separate lines with proper labels.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT