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

Using C# create a class that has a method implementing sequential search. create

ID: 3871005 • Letter: U

Question

Using C# create a class that has a method implementing sequential search. create a class as a tester, which will call the sequential search method in the first class

EXAMPLE using System;

using System.Collections.Generic;

using System.Linq; using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication30

{

class ProgramA

{

public static int SeqSearchB(int[] arr, int sValue)

{

for (int index = 0; index < arr.Length - 1; index++)

{

if (arr[index] == sValue) return index;

}

return -1;

}

public int SeqSearchA(int[] arr, int sValue)

{

for (int index = 0; index < arr.Length - 1; index++)

{

if (arr[index] == sValue) return index; } return -1;

}

}

class ProgramB

{

static void Main(string[] args)

{

int[] arrayInt = { 1, 4, 5, 7, 9, 10, 3, 8 };

int targetB = 19;

int searchResultIndex = 0;

searchResultIndex = ProgramA.SeqSearchB(arrayInt, targetB); Console.WriteLine("target=19, so result is {0}", searchResultIndex); ProgramA p = new ProgramA();

searchResultIndex = p.SeqSearchA(arrayInt, targetB); Console.WriteLine("target=19, so result is {0}", searchResultIndex); } } }

Explanation / Answer

using System;

using System.Collections.Generic;

using System.Linq; using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication30

{

class SequentialSearch

{

public static int SeqSearchB(int[] arr, int sValue)

{

for (int index = 0; index < arr.Length - 1; index++)

{

if (arr[index] == sValue) return index;

}

return -1;

}

public int SeqSearchA(int[] arr, int sValue)

{

for (int index = 0; index < arr.Length - 1; index++)

{

if (arr[index] == sValue) return index; } return -1;

}

}

class tester

{

static void Main(string[] args)

{

int[] arrayInt = { 1, 4, 5, 7, 9, 10, 3, 8 };

int targetB = 19;

int searchResultIndex = 0;

searchResultIndex = ProgramA.SeqSearchB(arrayInt, targetB);

Console.WriteLine("target=19, so result is {0}", searchResultIndex);

SequentialSearch p = new SequentialSearch();

searchResultIndex = p.SeqSearchA(arrayInt, targetB);

Console.WriteLine("target=19, so result is {0}", searchResultIndex); } } }

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