Exercise: Linear Search of an Array of Strings
Array: A collection of a fixed number of components all of the same data type.
When one-dimensional, the components are arranged in list form.
General Form:
dataType arrayName[intExp];
Examples: int scores[12],
string language[5] = {"C++","Java","JavaScript","PHP"};
Index: A non-negative integer that specifies the position of a component in an
array. For example:
language[4] = "SQL";
0. Declare and initialize SIZE--a named program constant with value 9.
1. Declare item[] to have nine string components. Include the assignment of
these initial element values {"banana","tomato","lettuce","bread","tea",
"turkey","oatmeal","cookies","yogurt"} to item.
2. Code and invoke printArray(), a void function with the formal parameter
item[] and is to print item[] values to the console.
3. Prompt and input searchItem, a string value to locate in item[].
4. Declare an int named position for the array index and initialize it to the
value 0; and declare found a boolean initialized to false to indicate the
searchItem value has not yet been found in item[].
5. Perform a linear search on item[] comparing the argument searchItem
with each element of item[] until a match is found or the end of the array
is reached. If searchItem equals an array element value, set found to true;
otherwise increment position. After the search, if found equals true output
the array position(i.e. 0, 1,...,8); otherwise print a message that the
searchItem value was not found in item[].