Menu

(Solved) : Part 1 50 Marks Goal Develop Program Used Perform Keyword Searches Text Files Local Direct Q27719678 . . .

Part 1 [50 marks]

Your goal is to develop a program that can be used to performkeyword searches in a text files in the local directory. Say youyour local directory contains the following files (text files withextension .txt)

$ ls…dog.jpgfile1.txtfile2.txtpride and prejudice.txtgilgamesh.txtemma by jane austin.txt

When we run your program as follows

$ ./search <keyword-1> <keyword-2> <keyword-3>

The program will produce the following output

keyword-1: Found in “file1.txt” at line 3 Found in “file2.txt” at line 4 Found in “gilgamesh.txt” at line 3 (2 times)keyword-2: Not foundkeyword-3: Found in “emma by jane austin.txt” at line 73 (5 times)

Note that dog.jpg was ignored, since it doesn’t have .txtextension.

Part 2 [30 marks]

In the previous part, your program processes thedatabase (meaning, the list of text files in the currentfolder) anew each time it is used to perform search. This clearlycannot scale. Can you think of ways where the program doesn’t haveto process the entire database everytime a search is performed?

So then

$ ./search –make-index

will process the database, saving the relevant info, and

$ ./search <keyword-1> <keyword-2> <keyword-3>

will behave as before (except now it won’t have to process thedatabase from scratch every time a search is performed). Brieflydescribe your solution.

Is it any faster?

Programming suggestions

You are free to use all of STL for part 1 and part 2 of thisassignment.

To those of you are feeling adventurous, I suggest that you lookinto Boost C++ for figuring out how to find the list of files inthe current directory.

If Boost C++ library is not your cup of tea, you may want tolook at the DIR structure available in dirent.h to find the list offiles in a directory.

It is worthwhile to look at std::map structure for setting upindices for quick seach queries.

PLEASE POST THE CODE THANKS

Expert Answer


Answer to Part 1 50 Marks Goal Develop Program Used Perform Keyword Searches Text Files Local Direct Q27719678 . . .

OR