Assignment
2 - Arrays, Sorting and Searching
due
October 6th
The
purpose of this assignment is to give you practice working with arrays,
passing them to functions, sorting, searching and reading and writing
text files.
In
this program you will read two files and store their contents in
arrays. You will sort both arrays, and then search an array
for each element of the second array.
Program
Steps
- Open two input files and one output file.
- Read in these two files and store their contents in 2
arrays of strings. Do not use a vector.
- Sort both arrays using a selection sort.
Use the same
sort routine for
sorting both arrays. Do not use the STL sort
algorithm or quick sort.
- Search the dictionary
array for each gettysburg word (that's the words contained in the second file).
If the gettysburg word is not present in the dictionary array,
write a message to the output file that the gettysburg word is not
found in the dictionary
(see sample output below). Count the number of gettysburg words not found.
You will print this number at the end of the program.
Your search must be a binary search.
Output
Details
Required
console
output
Number
of gettysburg words not found = ??
<= the number is less than 30
Required
file
output
Gettysburg Words not found in the dictionary advanced ago as birth by civil consecrated continent detract equal government ground ... |
Additional
Requirements
You
must include at least two additional functions:
- a sort function
- a binary search function that looks for each keyword in the
dictionary array. You may use a function that is similar to
the one that was presented in class.
Place
the function definitions below main() and function prototypes above
main().
Hints
- The
string class has less than, greater than, and equal operators (that's
<, >, and ==). You'll find those quite useful
for sorting
and searching.
- Try working with small dictionary and small gettysburg word files while you are developing your code. The logic
is
the same for a small file as it would be for large files. It
will be easier to debug your code with smaller files. After
you
get it working, switch over to the larger files.