Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ In this project you are going to implement a Bag class to function as a word search engine program. The program allows users to

C++

In this project you are going to implement a Bag class to function as a word search engine program. The program allows users to find words among a given set of text files. The program takes a path to a directory as an input. The directory contains a set of files consisting of multiple words. A word can appear multiple times in a single file, or in multiple files. The program reads all the files, parses file content into words, and feeds the words to a Bag object.

You are also provided with bag.h and main.cpp. In bag.h, there are some public functions declared for you. Your task is to implement those functions in a source code file named bag.cpp. You are REQUIRED to use array(s) to store words and associated information in the bag. If you use data structures other than array(s), you will NOT be awarded any credit.

class bag

Bag (int max_num_words = 10000);

Constructor that takes an integer to denote the maximum number of words in a bag. Default value is 10000.

virtual ~Bag ();

Destructor that you need to release the dynamically allocated memory at the end of the object life cycle.

void insert(const string& word, const string& fileName, int count);

Inserts a word, the name of a file in which it appears, and the number of occurrences of the word in that file into the bag.

pair lookupFirst(const string& word);

lookup for the first file in insertion order that contains the search word. A pair containing the filename and associated count is returned if the word is found in the bag. A pair with an empty string and 0 is returned if the word is not in the bag.

pair Bag::lookupRandom(const string& word)

Similar to lookupFirst, but lookupRandom looks up a random file ( and associated count) that contains the word. Note that every file in which the word appears should have an equal chance to be returned.

void Bag::lookupAll(const string& word, vector< pair >&items)

lookupAll finds all the files that contain the search word, and returns a vector of pairs of the file name and associated count.

You can add private member variables and functions at the corresponding places in bag.h, but you should NOT modify other parts of the header file

I need the LookupRandom and lookupAll functions any suggestions based upon the description of the functions? Here is what I have for lookupFirst function.

pair Bag::lookupFirst(const string& word) {

unsigned int index;

for (int i=0; i; else index = i; return pair; }

}

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

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago