Преобразовать эту программу в программу с классами - C#
Формулировка задачи:
Суть такова. Должно быть 2 класса (КЛАСС где рандомно забивается массив, и класс где происходит бинарный поиск.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication64
{
class Program
{
static void Main(string[] args)
{
Console.Write("Введите кол-во элементов массива N: ");
int g=10, count=0, m=-2, x;
x = 0;
int[] n = new int[g + 1];
Massive.Rand(n, g);
Massive.BinarSort(n, g);
Console.WriteLine("Искомый элемент X = {0} находится на позиции m = {1}", x, m + 1);
Console.WriteLine("Кол-во раз прохода по циклу {0}", count);
Console.WriteLine("Повторить поиск? (y/n)");
Console.Clear();
}
class Massive
{
public static void Rand(int[] n, int g)
{
Random rnd = new Random();
for (int i = 0; i < g; i++)
{
n[i] = rnd.Next(-50, 50);
Console.Write(n[i].ToString() + " ");
}
}
public static void BinarSort(int[] n, int g )
{
int x, a, b, count, m = -2;
Array.Sort(n);
string question;
do
{
question = "y";
count = 0;
for (int i = 0; i < g; i++)
{
Console.Write("{0} ", n[i]);
}
Console.WriteLine();
Console.Write("Введите искомый элемент массива X: ");
x = int.Parse(Console.ReadLine());
a = 0;
b = g;
while (a != b)
{
count++;
m = (a + b) / 2;
if (n[m] == x)
{
a = b;
}
else
{
if (n[m] < x)
{
a = m + 1;
}
else
{
b = m;
}
m = -2;
}
}
}
while (question == "y");
}
}
}
}Решение задачи: «Преобразовать эту программу в программу с классами»
textual
Листинг программы
static class ArrayGenerator
{
public static int[] GenerateArray(int size, int min = -50, int max = -50)
{
int[] result = new int[Math.Abs(size)]; // случаи разные бывают
Random rnd = new Random();
for (int i = 0; i < size; i++)
result[i] = rnd.Next(min, max);
return result;
}
}
static class ArrayFinder
{
public static void BinarySort(int[] n, int g)
{
int x, a, b, count, m = -2;
Array.Sort(n);
string question;
do
{
question = "y";
count = 0;
for (int i = 0; i < g; i++)
{
Console.Write("{0} ", n[i]);
}
Console.WriteLine();
Console.Write("Введите искомый элемент массива X: ");
x = int.Parse(Console.ReadLine());
a = 0;
b = g;
while (a != b)
{
count++;
m = (a + b) / 2;
if (n[m] == x)
{
a = b;
}
else
{
if (n[m] < x)
{
a = m + 1;
}
else
{
b = m;
}
m = -2;
}
}
}
while (question == "y");
}
}