← Back to STL Containers
Question 474
Unique Word Tracker
Unique Word Tracker
Build a classUniqueWordsthat stores the distinct words in aset<string>. It must provide these public methods: 1.void add(const string& word): records the word. Every call counts toward the total, but a word that was added before does not increase the unique count. 2.int unique() const: returns how many distinct words have been added. 3.int totalAdded() const: returns how many timesaddhas been called in total, including repeats. 4.bool seen(const string& word) const: returns true if the word has been added at least once, false otherwise. 5.void printSorted() const: prints each distinct word on its own line in alphabetical order. Prints nothing at all if no words were added. The test prints the labels itself. After adding apple, pear, apple, kiwi, pear (in that order) (see Expected Output). Do NOT write a main function.
Expected Output:
Unique: 3 Total: 5 apple kiwi pear Unique: 0 Total: 0 true false zebra
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
STL ContainersSets
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.