Question: 1. In a C++ class definition for an abstract data type WordTree of strings, store the words and the counts of the words in a

1. In a C++ class definition for an abstract data type WordTree of strings, store the words and the counts of the words in a single binary search tree. Each word occurring in the text can only be stored once in the tree. Implement each member function in the class below. The WordTree class may have only one member variable, root, and it must be private. provide an appropriate copy constructor, destructor and assignment operator for the WordTree class as well.

 #include  #include  using namespace std; typedef string ItemType; struct WordNode { ItemType m_data; WordNode *m_left; WordNode *m_right; // You may add additional data members and member functions in WordNode }; class WordTree { private: WordNode *root; public: // default constructor WordTree() : root(nullptr) { }; // copy constructor WordTree(const WordTree& rhs); // assignment operator const WordTree& operator=(const WordTree& rhs); // Inserts val at the front of the list void add(ItemType v); // Returns the number of distince words / nodes int distinctWords() const; // Returns the total number of words inserted, including duplicate // values int totalWords() const; // Prints the LinkedList friend ostream& operator<<(ostream &out, const WordTree& rhs); // Destroys all the dynamically allocated memory // in the tree. ~WordTree(); }; 

The add function enables a client to insert elements into the WordTree. If an element has already been added, repeated calls to add will not add a new WordNode. Instead the count of the occurrences of that word will increase.

The key and the number of occurrences of the key are printed. The output should be sorted according to the key.

2. implement overloading the output operator in a class as a non member friend function.

When comparing items, just use the == or != operators provided for the string type by the library. These do case-sensitive comparisons. In other words, the The THE will count as different words.

3. write a main routine and the WordTree member functions.

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!