111k views
1 vote
Write a program that takes paragraph from the user and prints all unique words in that paragraph using strings in c++

1 Answer

0 votes

Answer:

void printUniquedWords(char filename[])

void printUniquedWords(char filename[]) {

void printUniquedWords(char filename[]) { // Whatever your t.text file is

fstream fs(filename);

fstream fs(filename);

fstream fs(filename);

fstream fs(filename); map<string, int> mp;

fstream fs(filename); map<string, int> mp;

fstream fs(filename); map<string, int> mp; // This serves to keep a record of the words

string word;

string word; while (fs >> word)

string word; while (fs >> word) {

string word; while (fs >> word) { // Verifies if this is the first time the word appears hence "unique word"

if (!mp.count(word))

if (!mp.count(word)) mp.insert(make_pair(word, 1));

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++;

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; }

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; }

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close();

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close();

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count //is 1

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count //is 1 for (map<string, int> :: iterator p = mp.begin();

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count //is 1 for (map<string, int> :: iterator p = mp.begin(); p != mp.end(); p++)

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count //is 1 for (map<string, int> :: iterator p = mp.begin(); p != mp.end(); p++) {

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count //is 1 for (map<string, int> :: iterator p = mp.begin(); p != mp.end(); p++) { if (p->second == 1)

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count //is 1 for (map<string, int> :: iterator p = mp.begin(); p != mp.end(); p++) { if (p->second == 1) cout << p->first << endl;

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count //is 1 for (map<string, int> :: iterator p = mp.begin(); p != mp.end(); p++) { if (p->second == 1) cout << p->first << endl; }

if (!mp.count(word)) mp.insert(make_pair(word, 1)); else mp[word]++; } fs.close(); // Traverse map and print all words whose count //is 1 for (map<string, int> :: iterator p = mp.begin(); p != mp.end(); p++) { if (p->second == 1) cout << p->first << endl; } }

User Steve Gilham
by
4.9k points