Question

In: Computer Science

Develop a C# console application that will implement one method that will return an integer value,...

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. Please 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 get random method 20 times. In the loop, you will pass a seed value to the get random 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 getRandommethod, 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 to get random 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 an 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 calculation 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. and I want the screenshot of the output too.

Solutions

Expert Solution

using System;


namespace week7
{
class Program
{
static void Main(string[] args)
{

int randomNumber;//hold random
double average = 0;//hold average
double total = 0;//hold total
double manualEntry = 0; //input entry 

for(int i = 0; i < 20; i++)//20 times
{
randomNumber = getRandom();//by reference

total = total + randomNumber;//by reference
}

calculate(total, ref average, 20);



Console.WriteLine("The average of the 20 random numbers is {0}", average);

total = 0;
Console.WriteLine();//adds space

for (int i = 0; i < 5; i++)
{ 
Console.Write("Enter a double value ");
manualEntry = Convert.ToDouble(Console.ReadLine());
calculate(manualEntry, ref total);



}
Console.WriteLine("The total is {0}",total);

}

static int getRandom()
{
Random randomGenerator = new Random();
return randomGenerator.Next(1,101);
}

//pass the total of the random values, the average variable by reference, and the literal value of 20.


// the entry taken from the console and the variable to hold the total by    reference. 
private static void calculate(double consoleInput, ref double total)
{
total += consoleInput;
}
//pass the total of the random values, the average variable by reference, and   the literal value of 20.
private static void calculate(double total, ref double average, double          denominator)
{
average = total / denominator;
}
}
}

Related Solutions

Write a C++ console application to simulate a guessing game. Generate a random integer between one...
Write a C++ console application to simulate a guessing game. Generate a random integer between one and 100 inclusive. Ask the user to guess the number. If the user’s number is lower than the random number, let the user know. If the number is higher, indicate that to the user. Prompt the user to enter another number. The game will continue until the user can find out what the random number is. Once the number is guessed correctly, display a...
Design and implement an application that reads an integer value and prints the sum of all...
Design and implement an application that reads an integer value and prints the sum of all even integers between 2 and the input value, inclusive. Print an error message if the input value is less than 2 and prompt accordingly so that the user can enter the right number. Your program file will be called YourLastNameExamQ2
            It is not uncommon to develop the logic of a program as a console application...
            It is not uncommon to develop the logic of a program as a console application (NO GUI) and then graft a GUI on to it later. There are also many reasons for separating the GUI of the program from the rest of the code logic. (This is part of a common design pattern called Model View Controller (MVC) where the GUI represents the View aspect.) For instance, you might have a Web-based or mobile device GUI in addition to...
Write a recursive method that displays an integer value reversely on the console using the following...
Write a recursive method that displays an integer value reversely on the console using the following header: public static void reverseDisplay(int value) For example, reverseDisplay(12345) displays 54321. Write a test program that prompts the user to enter an integer, invokes the method above, and displays its reversal.
programming language is c#. Create a method that prompts a user of your console application to...
programming language is c#. Create a method that prompts a user of your console application to input the information for a student: static void GetStudentInfo() { Console.WriteLine("Enter the student's first name: "); string firstName = Console.ReadLine(); Console.WriteLine("Enter the student's last name"); string lastName = Console.ReadLine(); // Code to finish getting the rest of the student data ..... } static void PrintStudentDetails(string first, string last, string birthday) { Console.WriteLine("{0} {1} was born on: {2}", first, last, birthday); } 1. Using the...
Create a C# Windows Console application that displays the following patterns separately, one after the other....
Create a C# Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to the next line. A statement of the form Console.Write(" "); can be used to display a space for the...
Implement the addSecond method in IntSinglyLinkedList. This method takes an Integer as an argument and adds...
Implement the addSecond method in IntSinglyLinkedList. This method takes an Integer as an argument and adds it as the second element in the list. Here is an example of adding the Integer 7 to a list with two elements. Abstract view: addSecond(7) on the list [12, 100] turns the list into [12, 7, 100] Implement the rotateLeft method in IntSinglyLinkedList. It moves all elements closer to the front of the list by one space, moving the front element to be...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
with C# create a console application project that outputs the number of bytes in memory that...
with C# create a console application project that outputs the number of bytes in memory that each of the following number types use, and the minimum and maximum values they can have: sbyte, byte, short, ushort, int, uint, long, ulong, float, double, and decimal. Try formatting the values into a nice-looking table! More Information: You can always read the documentation, available at https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting for Composite Formatting to learn how to align text in a console application. Your output should look...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT