Question

In: Computer Science

A very common application of arrays is computing statistics on lists of numbers. Below you will...

A very common application of arrays is computing statistics on lists of numbers. Below you will find a template of a program that uses four user-defined methods: input an array of numbers, compute the average the array, find the largest number in the array, and find the smallest number in the array. Enter the following program into C# (ignore the line numbers) and replace the lines marked with // *** with the appropriate C# code (may require more than one line of code to complete the missing parts).

// Name: xxxxxxxxxxxxx
// Student Number: xxxxxxx
// Lab 4, Part 2
// Program Description: This program uses four user-defined methods: one
//    to input an array of numbers, one to compute the average the array, one 
//    to find the largest number in the array, and one to find the smallest 
//    number in the array.
 
using System;
public static class Lab4_2
{
   public static void Main()
   {
      int[] compStats = new int[25];
      int n = 0, large, small;
      double avg = 0;
 
      // Input values into the array
      InpArray(compStats, ref n);

      // Find the average of the elements in the array
      // *** Insert the code for the call to the FindAverage method
 
      // Find the largest element in the array
      // *** Insert the code for the call to the FindLarge method
 
      // Find the largest element in the array
      // *** Insert the code of the call to the FindSmall method
 
      // Print out the results
      Console.WriteLine("\nThe Average of the array is {0:F}", avg);
      // *** Insert the code to print out the largest and smallest values
 
      // Pause until user is done
      Console.ReadLine();
   }
 
   // Method:       InpArray
   // Description:  Input values into an array.
   // Parameters:   arrValues: the array to fill.
   //               num: number of elements in the array.
   // Returns:      void
   public static void InpArray(int[] arrValues, ref int num)
   {
      // input the number of data values to put in the array
      do
      {
          Console.Write("Enter the number of elements (<= 25) => ");
          num = Convert.ToInt32(Console.ReadLine());
      } while (num < 0 || num > 25);
 
      // loop to enter the values
      for (int i = 0; i < num; ++i)
      {
          Console.Write("Enter the Element {0} => ", i);
          arrValues[i] = Convert.ToInt32(Console.ReadLine());
      }
   }
 
   // Method:       FindAverage
   // Description:  Computes the average of the elements in the array.
   // Parameters:   arrVals: array to be processed
   //               num: number of elements in the array.
   // Returns:      the average of the elements in the array
   public static double FindAverage(int[] arrVals, int num)
   {
      // *** Insert the details of the FindAverage Method
   }
 
   // Method:       FindLarge
   // Description:  Determines the largest element in the array.
   // Parameters:   arrVals: array to be processed
   //               num: number of elements in the array.
   // Returns:      the largest element in the array
   public static int FindLarge(int[] arrVals, int num)
   {
      // *** Insert the details of the FindLarge Method
   }
 
   // Method:       FindSmall
   // Description:  Determines the smallest element in the array.
   // Parameters:   arrVals: array to be processed
   //               num: number of elements in the array.
   // Returns:      the smallest element in the array
   public static int FindSmall(int[] arrVals, int num)
   {
      // *** Insert the details of the FindSmall Method
   }
}

Solutions

Expert Solution

C# Code:

// Name: xxxxxxxxxxxxx
// Student Number: xxxxxxx
// Lab 4, Part 2
// Program Description: This program uses four user-defined methods: one
// to input an array of numbers, one to compute the average the array, one
// to find the largest number in the array, and one to find the smallest
// number in the array.

using System;
public static class Lab4_2
{
public static void Main()
{
int[] compStats = new int[25];
int n = 0, large, small;
double avg = 0;

// Input values into the array
InpArray(compStats, ref n);

// Find the average of the elements in the array
avg = FindAverage(compStats, n);

// Find the largest element in the array
large = FindLarge(compStats, n);

// Find the largest element in the array
small = FindSmall(compStats, n);

// Print out the results
Console.WriteLine("\nThe Average of the array is {0:F}", avg);
Console.WriteLine("\nThe Largest of the array is {0}", large);
Console.WriteLine("\nThe Smallest of the array is {0}", small);

// Pause until user is done
Console.ReadLine();
}

// Method: InpArray
// Description: Input values into an array.
// Parameters: arrValues: the array to fill.
// num: number of elements in the array.
// Returns: void
public static void InpArray(int[] arrValues, ref int num)
{
// input the number of data values to put in the array
do
{
Console.Write("Enter the number of elements (<= 25) => ");
num = Convert.ToInt32(Console.ReadLine());
} while (num < 0 || num > 25);

// loop to enter the values
for (int i = 0; i < num; ++i)
{
Console.Write("Enter the Element {0} => ", i);
arrValues[i] = Convert.ToInt32(Console.ReadLine());
}
}

// Method: FindAverage
// Description: Computes the average of the elements in the array.
// Parameters: arrVals: array to be processed
// num: number of elements in the array.
// Returns: the average of the elements in the array
public static double FindAverage(int[] arrVals, int num)
{
double sum = 0;
for(int i = 0; i < num; i++)
{
sum += arrVals[i];
}
return sum / num;
}

// Method: FindLarge
// Description: Determines the largest element in the array.
// Parameters: arrVals: array to be processed
// num: number of elements in the array.
// Returns: the largest element in the array
public static int FindLarge(int[] arrVals, int num)
{
int large = arrVals[0];
for (int i = 1; i < num; i++)
{
if(large< arrVals[i])
{
large = arrVals[i];
}
  
}
return large;
}

// Method: FindSmall
// Description: Determines the smallest element in the array.
// Parameters: arrVals: array to be processed
// num: number of elements in the array.
// Returns: the smallest element in the array
public static int FindSmall(int[] arrVals, int num)
{
int small = arrVals[0];
for (int i = 1; i < num; i++)
{
if (small > arrVals[i])
{
small = arrVals[i];
}

}
return small;
}
}

Sample Output:

Enter the number of elements (<= 25) => 5
Enter the Element 0 => 15
Enter the Element 1 => 23
Enter the Element 2 => 456
Enter the Element 3 => 23
Enter the Element 4 => 10

The Average of the array is 105.40

The Largest of the array is 456

The Smallest of the array is 10


Related Solutions

Write a very general sort method that can sort any type of data arrays/lists. For example,...
Write a very general sort method that can sort any type of data arrays/lists. For example, can sort a list of integers in ascending order, a list of integers in descending order, a list of doubles, a list of student objects (with names and scores) in ascending order of names, or in descending order of scores, … You can use any pre-defined sort function or can code your own. Use your favorite language for implementation. If your language doesn’t support...
USE JAVA. Write a very general sort method that can sort any type of data arrays/lists....
USE JAVA. Write a very general sort method that can sort any type of data arrays/lists. For example, can sort a list of integers in ascending order, a list of integers in descending order, a list of doubles, a list of student objects (with names and scores) in ascending order of names, or in descending order of scores, … You can use any pre-defined sort function or can code your own. Use your favorite language for implementation. If your language...
Code: C++ Write a very general sort method that can sort any type of data arrays/lists....
Code: C++ Write a very general sort method that can sort any type of data arrays/lists. For example, can sort a list of integers in ascending order, a list of integers in descending order, a list of doubles, a list of student objects (with names and scores) in ascending order of names, or in descending order of scores, … You can use any pre-defined sort function or can code your own. Use your favorite language for implementation. If your language...
The table below lists the numbers of words spoken in a day by each member of...
The table below lists the numbers of words spoken in a day by each member of randomly selected couples. Complete parts below. Use a 0.05 significant level to test the claim that among couples, males speak fewer words in a day than females. Female 27000 16870 28783 25177 21677 17178 26813 23831 Male 22665 23117 17592 12991 11902 20167 14957 20671 First, you need to check the requirements. 1) it is a __________ _________ Sample; 2) either the number of...
The table below lists the numbers of words spoken in a day by each member of...
The table below lists the numbers of words spoken in a day by each member of randomly selected couples. Complete parts below. Use a 0.05 significant level to test the claim that among couples, males speak fewer words in a day than females. Female 27000 16870 28783 25177 21677 17178 26813 23831 Male 22665 23117 17592 12991 11902 20167 14957 20671 f. What is your conclusion ______________________________ and it means in this context:
. As input you are given two arrays: an array of numbers ? and an array...
. As input you are given two arrays: an array of numbers ? and an array ? of queries where each query is a target number. The array ? is unsorted and may contain duplicates. Your goal is, for each query ? in the array ?, count the number of pairs in the array ? that sums up to ?; that is, the number of distinct pairs of indices [?, ?], with ? < ?, such that ?[?] + ?[?]...
Of Temperature class Arrays are a very powerful data structure with which you must become very...
Of Temperature class Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The an object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many...
5. The table below lists situation in numbers by WHO regions as of May 27, 2020:...
5. The table below lists situation in numbers by WHO regions as of May 27, 2020: Country, Other Cases Deaths TOTAL CASES Africa 85,815 2,308 Americas 2,495,924                      2,641,734.00 Eastern Mediterranean 11,452                          461,042.00 Europe 2,061,828                      2,238,054.00 South-East Asia 6,359                          224,882.00 Western Pacific 176,404 6,927 TOTALS 27,046                      5,837,166.00 a. Complete the totals. b. What is the probability that a randomly selected person in the Americas? c. What is the probability that a randomly selected person in Europe?...
So pretty much I need my code without the arrays, or lists. Please and thank you!...
So pretty much I need my code without the arrays, or lists. Please and thank you! Important: You may not use arrays, lists, or similar for your questions. This will be covered in the next module. The objective is to use conditionals in order to achieve the overall task. Checkpoint 3 is a continuation of the “Quiz” Programming Project. This module week, you will implement repetitive tasks in your program while using conditional and iteration statements in C#. Implement a...
Create a C++ file with given instructions below- Analyze random numbers Create two arrays, one int...
Create a C++ file with given instructions below- Analyze random numbers Create two arrays, one int one double. They should have 10 elements each Ask the user how many random numbers to generate. Then generate that many random numbers between 1 and 10. Use a for loop. Keep track of how many of each number in the range was generated (1 to 10) in the int array. Be sure to initialize the array to all 0's to start. Then, send...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT