This is a C Project Project specification In this project yo
This is a C++ Project.
Project specification: In this project you are going to implement a word search engine using C++(and only C++ please). The search engine would help users to count number of occurrence of a word among given set of text files.
Input specification: The program takes as an input a set of files, containing of multiple words. Words can appear multiple times in a single file or in different files. The input files should be stored in a dedicated directory and loaded in memory upon program execution.
Program functionality:Upon execution, the program should load all the words from the input files in the memory. The program should run until the user explicitly specifies “exit”. The following functionality should be supported:
1. Count how many times a user specified word appears in the files.
2. Display the name of input files and corresponding number of occurrences of the specified word.
Upon execution of you program, you should specify as input parameter the path to a directory containing the input files. If executed (which somesone enters an input like \"cat\"), the program should return the name of files that contain the word \"cat\" and the number of occurrences of the word in each file
First, you need to implement a class for an abstract data type, in which you are going to store files in memory. This step is very specific, depending on the functionality of the program you are developing. For the current implementation you are required to use linked lists. A basic layout of the data structure you would need to implement is illustrated on the figure below:
You need to declare a class Word that would store a word and a pointer to the beginning of a linked list and another class File that would store a file-name and number of times that the word occurred in this file. The process of “loading files in the memory” consists of
(i) creating an object of type Word for each new word that occurs in the set of input files,
(ii) appending this object to a linked list (e.g. the green linked list from the picture),
(iii) creating an object File for each occurrence of the word in a file and
(iv) updating the corresponding (blue) linked list with the object File.
Once you have the files loaded in such structure, the searching would be as easy as finding the queried word in the “green” linked list and tracing in which files does it occur by going over the corresponding “blue” linked list. To start gaining experience in how to structure your C++ projects, you are required to split the different aspects of this program and implement them in separate files. Then you will have to put them all back together to achieve the program functionality. You will need to create several .h and .cpp files for this project.
First you need to identify the important object-types and methods you will need for your implementation. In this project, your main object types are going to be class Word and class File. Go ahead and create a file called itemtype.h and declare class File in it.
Then create another file called itemtype.cpp and define your class File in it. These two files are going to be related to objects from the “blue” lists on the picture. The next step is to implement the functionality for creating the “blue” lists. For this purpose, you need to create two more files – list.h and list.cpp. In list.h declare all the methods needed for building a “blue” list and in list.cpp define these methods.
Next, you need to implement the functionality related to objects like these in the “green” list. Create two more files – word.h and word.cpp, declare class Word and all methods to this class in word.h and define them in word.cpp. Now what\'s left is to put it all together by writing a main function that utilizes both file and word. To do so, create wordsearch.h and wordsearch.cpp, declare your main function in wordsearch.h and define it in wordsearch.cpp.
So all in all you will need eight files: wordsearch.h, wordsearch.cpp, itemtype.h, itemtype.cpp, list.h, list.cpp, word.h, word.cpp.
You need to submit 8 files. Eight of these are the implementation of your project assignment, namely wordsearch.h, wordsearch.cpp, itemtype.h, itemtype.cpp, list.h, list.cpp, word.h, word.cpp.
you are developing. For the current implementation you are required to use linked lists. A basic layout of the data structure you would need to implement is illustrated on the figure below: word 1 ptr list 1. count count count count file23 word 2 file5 ptr list 2 Lcount Count Count Count Word 3 ptr list 3 Count Count Count count Word n file3 ptr list count countSolution
#include <iostream> // library that contain basic input/output functions
#include <fstream> // library that contains file input/output functions
using namespace std;
int main()
{
int ocurrences_count = 0;
char word[20]; //this array will save user input
int array_size = 1024; // define the size of character array
char * array = new char[array_size]; // allocating an array of 1kb
int position = 0; //this will be used incremently to fill characters in the array
//prompting user to enter a word to be search in the file
cout << \"Please enter the word to search in file : \";
cin.getline(word,19); //reading user input of max 19 characters because our word array size in 20
int word_size = 0;
//this loop is calculating the length of input word
for(int i = 0; word[i] != \'\\0\'; i++)
{
word_size++;
}
ifstream fin(\"test.txt\"); //opening an input stream for file test.txt
/*checking whether file could be opened or not. If file does not exist or don\'t have read permissions, file
stream could not be opened.*/
if(fin.is_open())
{
//file opened successfully so we are here
cout << \"File Opened successfully!!!. Reading data from file into array\" << endl;
//this loop run until end of file (eof) does not occur
while(!fin.eof() && position < array_size)
{
fin.get(array[position]); //reading one character from file to array
position++;
}
array[position-1] = \'\\0\'; //placing character array terminating character
//this loop is searching for the word in the array
for(int i = 0; array[i] != \'\\0\'; i++)
{
for(int j = 0; word[j] != \'\\0\' && j < 20 ; j++)
{
if(array[i] != word[j])
{
break;
}
else
{
i++;
if(word[j+1] == \'\\0\')
{
cout << \"Word Found in File at position \" << (i-word_size) << endl;
ocurrences_count++;
}
}
}
}
cout << \"Total occurences found : \" << ocurrences_count << endl;
}
else //file could not be opened
{
cout << \"File could not be opened.\" << endl;
}
return 0;
}


