Question: When you read a long document, there is a good chance that many words occur multiple times. Instead of storing each word, it may be

When you read a long document, there is a good chance that many words occur multiple times. Instead of storing each word, it may be beneficial to only store unique words, and to represent the document as a vector of pointers to the unique words. Write a program that implements this strategy. Read a word at a time from cin. Keep a vector of words. If the new word is not contained in this vector, allocate memory, copy the word into it, and append a pointer to the new memory. If the word is already present, then append a pointer to the existing word.

Try to avoid using anything involving #include

Build off of this if possible:

#include

#include

#include

using namespace std;

int main ()

{

string wordInput;

vector words();

cout << "Begin entering your words. When finished type 'X!' to terminate.";

while (wordInput != "X!")

{

cin >> wordInput;

char*

}

return 0;

}

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!