Question: Can you please help me complete this code: WordItem.h #ifndef WORDITEM_H #define WORDITEM_H #include #include using namespace std; class WordItem { public: WordItem() :word(), count(0)
Can you please help me complete this code:
WordItem.h
#ifndef WORDITEM_H #define WORDITEM_H
#include
using namespace std;
class WordItem { public: WordItem() :word(""), count(0) {} WordItem(string wd) :word(wd),count(1) {} WordItem(constant WordItem& wd) : :word(wd.word),count(wd.count) {} int get_word() const { return word; }
int get_count() const { return count; }
void increase_count() { count++; } private: int word; int count; }; ostream& operator
List.h
#ifndef LIST_H #define LIST_H
#include
Node( const T & d = T{ }, Node * p = nullptr,Node * n = nullptr ) : data{ d }, prev{ p }, next{ n }{} };
public: class const_iterator { public: const_iterator( ) : current { nullptr } { }
const T & operator* ( ) const { return retrieve( ); }
const_iterator & operator++ ( ) { current = current->next; return *this; }
const_iterator operator++ ( int ) { const_iterator old = *this; ++( *this ); return old; } const_iterator & operator-- ( ) { current = current->prev; return *this; }
const_iterator operator-- ( int ) { const_iterator old = *this; --( *this ); return old; }
bool operator== ( const const_iterator & rhs ) const { return current == rhs.current; } bool operator!= ( const const_iterator & rhs ) const { return !( *this == rhs ); }
protected: Node *current;
T & retrieve( ) const { return current->data; }
const_iterator( Node *p ) : current{ p } { }
friend class List
T & operator* ( ) { return const_iterator::retrieve( ); } const T & operator* ( ) const { return const_iterator::operator*( ); }
iterator & operator++ ( ) { this->current = this->current->next; return *this; }
iterator operator++ ( int ) { iterator old = *this; ++( *this ); return old; } const_iterator & operator-- ( ) { this->current = this->current->prev; return *this; }
const_iterator operator-- ( int ) { const_iterator old = *this; --( *this ); return old; }
protected: iterator( Node *p ) : const_iterator{ p } { }
friend class List
~List( ) { clear( ); delete head; delete tail; }
List( const List & rhs ) { init( ); const_iterator itr = rhs.begin(); for (; itr != rhs.end(); ++itr) push_back( *itr ); }
List & operator= ( const List & rhs ) { List copy = rhs; std::swap( *this, copy ); return *this; } List( List && rhs ) : theSize{ rhs.theSize }, head{ rhs.head }, tail{ rhs.tail } { rhs.theSize = 0; rhs.head = nullptr; rhs.tail = nullptr; }
List & operator= ( List && rhs ) { std::swap( theSize, rhs.theSize ); std::swap( head, rhs.head ); std::swap( tail, rhs.tail );
return *this; }
iterator begin( ) { return iterator ( head->next ); } const_iterator begin( ) const { return const_iterator ( head->next ); } iterator end( ) { return iterator ( tail ); } const_iterator end( ) const { return const_iterator ( tail ); } // Erase item at itr. iterator erase( iterator itr ) { Node *p = itr.current; iterator retVal{ p->next }; p->prev->next = p->next; p->next->prev = p->prev; delete p; --theSize;
return retVal; }
// Insert x before itr. iterator insert( iterator itr, const T & x ) { Node *p = itr.current; ++theSize; return iterator ( p->prev = p->prev->next = new Node{ x, p->prev, p } ); } int size( ) const { return theSize; } bool empty( ) const { return size( ) == 0; }
void clear( ) { while( !empty( ) ) pop_front( ); } T & front( ) { return *begin( ); } const T & front( ) const { return *begin( ); } T & back( ) { return *--end( ); } const T & back( ) const { return *--end( ); } void push_front( const T & x ) { insert( begin( ), x ); } void push_back( const T & x ) { insert( end( ), x ); } void pop_front( ) { erase( begin( ) ); } void pop_back( ) { erase( --end( ) ); } private: int theSize; Node *head; Node *tail; void init( ) { theSize = 0; head = new Node; tail = new Node; head->next = tail; tail->prev = head; } }; #endif
Book.txt: you can use any text
This is the code i need help with Worditemain.cpp
#include
using namespace std;
template
int main() { list
template template string strip_punct(string x) { for (int i = x.size()-1; i >= 0; i--) { if (ispunct(x[i])) { x.erase(i--,1); i++; } else return x; } return x; } void alpha_insert(string x, list The output of this program need to count each word alphabetically and the upper cases first . it should be like this eample. 
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
