Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Write C Language Please Write Neatly Lab Combine Reading Data File Searching Array Find Sp Q35603931

Write In C++ Language

Please write neatly

This lab will combine reading data from a file and searching thearray to find a specific value.

Assignment

Write a program that reads in a file full of strings into anarray, and prompts the user for a string to find in the array. Theprogram should loop until a sentinel value (such as -1) isentered.

After looping in main() for the input, write a search function,with the following prototype:

int findWord(string [], int, string);

with arguments as follows:

1) The first argument, a string[] (array), is list of words readfrom the file.

2) The second argument, an ‘int’, is the maximum size of thefile (define a constant such as MAX_SIZE in main(), not as a globalvariable, and pass it into this function here). There are 10,000lines in the file.

3) The third argument, a ‘string’, is requested word to befound.

The return ‘int’ should be the position in the array where theword appears (starting with 0 for the first word) or the value -1if the word is not present in the array.

The input file is a list of dictionary words:dictionary_windows.txtPreview the document (Mac/Linuxusers should use this one: dictionary.txtPreview the document) — which youcan find in this week’s module.

How to Search

In your findWord function, use the linear searchalgorithm, which starts at the beginning of the array and thensteps through the elements sequentially until either the desiredvalue is found or the end of the array is reached.

For example, if the array is:

{ “hello”, “goodbye”, “sometimes”, “never” }

and we want to find the word “sometimes”, the algorithm wouldcheck each element, starting with “hello”, to see if it is equal tothe search key. When the search reaches either the foundword or the end of the array, the algorithm stops.

Example Output

Enter the word to find (-1 to exit): abacusThe word “abacus” is in the file at position 8884.Enter the word to find (-1 to exit): lifeThe word “life” is in the file at position 1.Enter the word to find (-1 to exit): -1

What to Submit

Upload your main.cpp file (source code for your solution) and ascreenshot of a single run with at least two lookups and an exit(i.e. entering ‘-1) to stop the program.

We were unable to transcribe this imageWe were unable to transcribe this imageShow transcribed image text

Leave a Reply

Your email address will not be published. Required fields are marked *