Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will be reading in 3 files in the program. One will contain a list of 1000 words in unsorted order. The second file will

You will be reading in 3 files in the program. One will contain a list of 1000 words in unsorted order. The second file will contain 1000 words in sorted order. The final file will contain 20 words to be searched for.

The main program has been written for you. You will be implementing three functions:

bool readWords(string array[], int size, string fileName);

int linearSearch(string wordToFind, const string words[], int size);

int binarySearch(string wordToFind, const string words[], int size);

The readWords function will read in from file fileName into the string array array. There will be size entries in the input file. If the file exists the function will read in the file and return true. If the file does not exist the function will return false.

The linearSearch function will use the linear search to see if wordToFind in in the array words. The size of the words array is size. As with the example in the text book your function will return -1 if the item is not found and the index in the array if it is found.

The binarySearch function will use a binary search to see If wordToFind exists in the array words. As with the example in the text book your function will return -1 if the item is not found and the index in the array if it is found.

The program should be named homework1.cpp.

A template for the assignment is on eLearning. The file of words to be found is named "findWords.txt", there are 20 words in this file. The file of unsorted words is "unsortedWords.txt" and the file of the sorted words is "sortedWords.txt". There are 1000 words in the "unsortedWords.txt" file and there are 1000 words in the "sortedWords.txt" file.

Note: The code in the text book for calculating the middle for the binary search is: middle = (first + last) / 2;

This will cause an overflow error some very big arrays (but not for the program you are writing).

Instead you should use: middle = first + (last - first) / 2;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago