Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION Develop a C# Console application in MS Visual C# 2010 that will impleme

ID: 3543894 • Letter: Q

Question

QUESTION                 

Develop a C# Console application in MS Visual C# 2010 that will implement one method that will return an integer                    value, one void method that will calculate an average, and one void overload for the calculate method that will compute a total.                 

Please read the requirements below carefully.                 

In Main:                 

In summary:                 

You will have Main in which you will declare 4 variables, a loop that will call a method that will return a random number, a call to a void                    calculate method which will take an integer random value variable, a byref average variable, a literal value of 20 as arguments and which will calculate an                    average, followed by a console writeline to display the average. This will be followed by a loop that will execute 5 times and will prompt for and assign a                    double value to a double variable and then call an overload of the calculate method and pass the entered value and a byref total variable. In the overloaded                    calculate method you will accumulate the passed value into the total variable. After the loop you will display the total.                 

The output might look similar to this:                 

The average of the 20 random numbers is 71

                    Enter a double value
11.11
                    Enter a double value 22.22
                    Enter a double value 33.33
                    Enter a double value 44.44
                    Enter a double value 55.55
                    The total is 166.65
                    Press any key to continue . . .

Explanation / Answer

//Open Visual studio. //Click File -> new -> Project //Click Console Application //Paste the following code in it
using System;
namespace ConsoleApplication4 { class myProgram { Random random = new Random(); public static void calculate(double total, ref double avg, int count) { avg = total / count; }
public static void calculate(double inputEntry, ref double total) { total+=inputEntry; }
public int getRandom() { return (int)this.random.Next(1, 100); }
static void Main(string[] args) { int randomValue; double avg = 0 ; double total=0; double inputEntry; myProgram myprogram = new myProgram();
for (int i = 0; i < 20; i++) { randomValue = myprogram.getRandom(); total += randomValue; } calculate(total, ref avg, 20); Console.WriteLine("The average of the 20 random numbers is " + avg); total = 0; for(int i=0;i<5;i++) { Console.Write("Enter a double value "); inputEntry = double.Parse(Console.ReadLine()); calculate(inputEntry, ref total); } Console.WriteLine("The total is " + total); Console.WriteLine("Press any key to continue . . ."); Console.ReadLine(); } } }