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

c# Write compile and test a program named IntegerStatistics. The programs Main()

ID: 3679891 • Letter: C

Question

c#

Write compile and test a program named IntegerStatistics. The programs Main() method will: 1. Declare an array of 10 integers. 2. Call a method to interactively fill the array with any number of values (up to 10) until a sentinel value is entered. [If an entry is not an integer, continue prompting the user until an integer is entered.] When fewer than 10 integers are placed into the array, your statistics will be off unless you resize the array to match the number of integers entered. Research the Array.Resize method to see how this can be done. 3. Call a second method that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and arithmetic average of values in the array. 4. Display all of the statistics

Explanation / Answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntegerStatistics
{
class Program
{
static void Main(string[] args)
{
int[] arrayInteger = new int[10];

Console.WriteLine("Option 1: Enter 1 for to provide all the 10 integer values.");   
Console.WriteLine("Option 2: Enter 2 for to provide fewer integer values.");
int optionResult = Convert.ToInt32(Console.ReadLine());
if (optionResult == 1)
{
for (int i = 0; i < 10; i++)
{
arrayInteger[i] = InteractivelyFill();
}
Console.WriteLine("All the 10 integer values entered.");
}
else if (optionResult == 2)
{
for (int i = 0; i < 10; i++)
{
arrayInteger[i] = InteractivelyFill();
Console.WriteLine("Are you want to resize whatever till now entered: Enter Y for Yes or N for Continue to Enter:");
string resultvalue = Console.ReadLine();
if (resultvalue.ToLower().Equals("y"))
{
Array.Resize(ref arrayInteger, i+1);
break;
}
}
if (arrayInteger.Length == 10)
Console.WriteLine("All the 10 integer values entered.");
else if (arrayInteger.Length > 0)
Console.WriteLine("Entered values to the Array List is: " + arrayInteger.Length.ToString());
}

DisplayStatistic(arrayInteger);

}

public static int InteractivelyFill()
{
int result = 0;
Console.WriteLine("Please enter integer value: ");
string enteredvalue = Console.ReadLine();
Int32.TryParse(enteredvalue, out result);
if (result.ToString() != enteredvalue)
{
Console.WriteLine("Enterd Valued is not an Integer. Please enter integer values only ");
InteractivelyFill();
}
return result;
}

static void DisplayStatistic(int[] arrayInteger)
{
var valueFromArray = arrayInteger.ToArray();
if (valueFromArray == null && valueFromArray.Length == 0)
{
Console.WriteLine("No Values in the Array");
return;
}
Console.WriteLine("Entered Values in the Array are: ");
foreach(var item in valueFromArray)
{
Console.WriteLine(item);
}

Console.WriteLine("Statistics Value :");
Console.WriteLine("------------------------------------");
Console.WriteLine("Highest Value from the array list is: " + valueFromArray.Max().ToString());
Console.WriteLine("Lowest Value from the array list is: " + valueFromArray.Min().ToString());
Console.WriteLine("Sum of all Value from the array list is: " + valueFromArray.Sum().ToString());
Console.WriteLine("Average Value from the array is: " + (valueFromArray.Sum()/valueFromArray.Length).ToString());
Console.ReadKey();
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote