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.
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to create a rectangle with user-specified height and width. 4. Method getArea() that returns...
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++ Application that: Interactively input: Employee First Name Employee Last Name Employee...
Design and implement a C++ Application that: Interactively input: Employee First Name Employee Last Name Employee id Employee hours worked per week Employee Pay Rate Menu with Option to: Print out Employee Report in the following report format Search for an Employee Display the Report in Sorted based on Last Name or ID Calculate the Pay Quit Criteria: Be sure to use Parallel Arrays to Store the Employee Information Output must be formatted and line up with the column header...
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...
In C ++, Design and implement a program that reads from the user four integer values...
In C ++, Design and implement a program that reads from the user four integer values between 0 and 100, representing grades. The program then, on separate lines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Format the outputs following the sample runs below. Sample run 1: You entered:    95, 80, 100, 70 Highest grade: 100 Lowest grade:   70 Average grade: 86.25
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT