Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a C# console application that will implement one method that will return an integer value, one void method that will calculate an average, and

Develop a C# console application 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.  Read the requirements below carefully.

In Main:

You will need four variables:  an integer value to hold a random value, a double value to hold an average, a double value to hold a total, and a double value to hold an input entry.

Using a for loop that will call a getRandom method 20 times.  In the loop you will pass a seed value to the getRandom method to use with the random generator and it will return a random value to be added to (accumulate) to the local integer variable in Main.  In the getRandom method you will generate a random value between 1 and 100  (see p241, section 7.9) and return that random value to Main.  The random value will be generated in getRandom using a Random class object.

Once the loop has completed the 20 method calls you will call a calculate method which returns no value and to which you will pass the total of the random values, the  average variable  by reference, and the literal value of 20.  In the calculate method you will compute and average by dividing the total of the random number passed in by the literal value 20 that was passed into the calculate method.

After the calculate method executes you will display the average to the console.

Following the writeline statement noted above, you will implement a second for loop that will process 5 iterations.  Within this for loop you will prompt the user to enter a double value from the console and then assign that input to the double variable declared to hold the input entry.  Also within the loop you will call an overload of the void calculate method and will pass two arguments:  the entry taken from the console and the variable to hold the total by reference.  The overload of the void calculate method will receive the double entry value and the byref double variable that will receive the total.  In the overloaded calculate method you will add the value passed in to the total variable.

After the overloaded calculate method executes you will display the total to the console.

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

Step by Step Solution

3.48 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

using System namespace week7 class Program static void Mainstring args int randomNumberhold random d... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Numerical Methods for Engineers

Authors: Steven C. Chapra, Raymond P. Canale

7th edition

978-0073397924, 007339792X, 978-0077492168, 77492161, 978-9352602131

More Books

Students also viewed these Programming questions

Question

What are the different techniques used in decision making?

Answered: 1 week ago

Question

Differentiate. y = ln(3x + 1) ln(5x + 1)

Answered: 1 week ago

Question

=+a. What is the probability that both tests yield the same result?

Answered: 1 week ago