In: Computer Science
Arrays Question:
You need to read in and process the wind speeds in East London over
the past few days. The maximum number of days are 8. Implement the
methods listed below. Then use these methods effectively to read in
the marks wind speeds and display the minimum and maximum speeds.
You may not change any methods – including their
parameters. static public int getValidNumber(int a, int b)
//Returns a number between a and b – including a and b
//You may assume that a <= b static public void
ReadSpeedsIntoArray (int[] list, ref int NrEl)
// Reads wind speeds into an array. Request from the user how
many
// wind speeds need to be read in. At least 4 speeds must be
read
// in, but not more than 10. A speed cannot be negative or
higher
// than 150. static public void getMinMax (int[] list, int NrEl,
out int Min, out int Max )
// Returns the minimum and the maximum wind speed recorded in list
static public void displayMinMax (int[] list, int NrEl)
// Displays the minimum and maximum wind speeds recorded in
list
it's C# language
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
Code:
using System;
public class MainClass {
static public int getValidNumber(int a, int b)
{
Random r = new Random();
int number = r.Next(a, b);
return number;
}
static public void ReadSpeedInttoArray(int[] list, ref int NrEl)
{
int n;
do
{
Console.WriteLine("How many readings(min 4)");
n = Convert.ToInt32(Console.ReadLine());
if (n > 8)
{
Console.WriteLine("number of readings cannot be more than 8");
}
if (n < 4)
{
Console.WriteLine("Please enter readings 4 or more");
}
} while ( n < 4 || n > 8 );
for (int i = 0; i < n; i++)
{
list[i] = getValidNumber(0, 150);
}
NrEl = n;
}
static public void getMinMax(int[] list, int NrEl, out int min, out int max)
{
min = list[0];
max = list[0];
for (int i = 0; i < NrEl; i++)
{
if (max < list[i])
{
max = list[i];
}
if (min > list[i])
{
min = list[i];
}
}
}
static public void diplayMinMax(int[] list, int NrEl)
{
Console.WriteLine("List of Windspeeds: ");
for (int i = 0; i < NrEl; i++)
{
Console.Write("{0} ", list[i]);
}
int min,
max;
getMinMax(list, NrEl, out min, out max);
Console.WriteLine("\n\nMinimum windspeed : {0}", min);
Console.WriteLine("\nMaximum windspeed: {0}", max);
}
public static void Main(string[] args) {
int[] list = new int[8];
int n = 0;
ReadSpeedInttoArray(list, ref n);
diplayMinMax(list, n);
}
}
Output: