Question: Hello, I needed some help with this C++ assignment: Program Challenge 7 Page 1120 Word Index Write a program that reads the contents of a

Hello, I needed some help with this C++ assignment:

Program Challenge 7 Page 1120

Word Index

Write a program that reads the contents of a text file. The program should create a map in which the

keys value pairs are described as follows:

Key The keys are the individual vords found in the file.

Values Each value is a set that contains the line numbers in the file where the word (the key) is

found.

For example, suppose the word robot is found in line 7, 18, 94 and 138. The map would contain an

element in which the key was the string robot, and the value was a set containing the numbers 7, 18,

94, and 138.

Once the map is built the program should create another text file, known as a word index, listing the

contents of the map. The word index file should contain an alphabetical listing of the words that are

stored as keys in the map, along with the line numbers where the words appear in the original file.

------------------------------------------------------------------------

Was also given this starting code:

#include

#include

#include

#include

#include

#include

using namespace std;

// Function prototypes

void split(const string &, char, vector &);

bool openFile(ifstream &);

bool buildMap(map> &);

void writeIndex(map>);

string trim(string &);

int main()

{

fstream inFile;

string temp;

bool testB;

inFile.open("First.txt", fstream::in);

if (inFile.is_open())

{

inFile >> temp;

}

else

{

cerr << "File opennig failure";

}

return 0;

}

// Function prototypes

void split(const string &, char, vector &)

{

};

bool openFile(ifstream &filename)

{

bool testB = false;

//testB = (getline(filename, temp));

if (filename)

{

testB = true;

}

return testB;

};

bool buildMap(map> &First)

{

return true;

};

void writeIndex(map> )

{

};

string trim(string &str1)

{

return str1;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!