Question: C# SAMPLE CODE: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Linear_Search { /// /// /// Demonstrates a Linear Search on an array of
C#

SAMPLE CODE:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Linear_Search { /// /// /// Demonstrates a Linear Search on an array of strings /// /// author: Mike Roggenkamp /// /// date: March 2009 /// /// class Program { static void Main(string[] args) { const string Start_Message = " \tWelcome to Linear Search Demonstration " + " The array contains the following 9 words: "; string[] words = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}; int location; OutputMessage(Start_Message); DisplayArray(words); location = LinearSearch(words, "the"); OutputSearchResult(location, "the"); location = LinearSearch(words, "able"); OutputSearchResult(location, "able"); location = LinearSearch(words, "over"); OutputSearchResult(location, "over"); location = LinearSearch(words, "zebra"); OutputSearchResult(location, "zebra"); location = LinearSearch(words, "dog"); OutputSearchResult(location, "dog"); ExitProgram(); } //end Main /// /// Linear search of "words" for the "word" /// /// list of words to be searched /// the word being searched for /// position of "word" in "words" if it is there /// otherwise returns -1 public static int LinearSearch(string[] words, string word) { int position = 0; /* * while ((position /// Displays the elements of the array "words" /// /// array to be displayed static void DisplayArray(string[] words) { foreach (string element in words) { OutputMessage("\t" + element + " "); } Console.WriteLine(); }//end DisplayArray /// /// Displays the outcome of the linear search /// /// either the position of "word" if it was found /// or -1 if "word" was not found /// static void OutputSearchResult(int position, string word) { string continueMessage = " Press any key to continue:"; if (position /// Outputs the string "s" /// /// String to be output static void OutputMessage(string s) { Console.Write(s); }// end OutPutMessage static void ExitProgram() { OutputMessage(" Press any key to exit program: "); Console.ReadKey(); }//end ExitProgram }//end class }//end namespace
Your task is to complete the LinearSearch' function, which has been outlined in the form of pseudocode, in the provided test framework. Upon completing the LinearSearch functio you should get output that looks like this (after pressing enter enough times) Welcone to Linear Search Denonstration The array contains the following 9 words: the uick rown jumps over the lazy dog he word "the" found in position in the list Press any key to continue he word "able" not found in the list Press any key to continue he word "over"found in position 5 in the list he s so anyxehra con found in the list Press any key to continue: he word "dog" found in position 8 in the list Press any key to continue: Press any key to exit program:_ Implement the LinearSearch function as defined by the specification. It should take two arguments: an array of strings and a string to search for and return the position of that string in the array or -1 if the string was not found in the array. If th e array contains multiple copies of the search string, you should return the first position the string appears in. Note that the Main() function of the provided code is never called- only the LinearSearch() function is called in order to test your program. As a result, there is no problem is the program uses ReadKey (). However, it also means your LinearSearch) method must be public
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
