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 #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 using namespace std; template class List { private: struct Node { T data; Node *prev; Node *next;

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; }; class iterator : public const_iterator { public: iterator( ) { }

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; }; public: List( ) { init( ); }

~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 #include #include "WordItem.h" #include "List.h"

using namespace std;

template void print_list(list); template void print_lines(list); void alpha_insert(string, list&); string strip_punct(string);

int main() { list wdList; string next; ifstream inp; inp.open("Book.txt"); inp >> next; next = strip_punct(next); while (!inp.fail()) { alpha_insert(next, wdList); // HW2: DEFINE BELOW inp >> next; next = strip_punct(next); // HW2: DEFINE BELOW } inp.close(); // HW2: Print out each word and its number of occurrence // in "from_steven_king_it"; word:count pair per alpha_insert // HW2: Iterate over the wdList and determine the word // among all WordItems that has maximal count; // HW2: export this most frquent word and its count; return 0; }

template void print_list(list lst) { cout ::iterator itr; for (itr = lst.begin(); itr != lst.end(); ++itr) cout

template void print_lines(list lst) { cout ::iterator itr; for (itr = lst.begin(); itr != lst.end(); ++itr) cout

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& wdlst) { WordItem wordit; if (wdlst.empty()) { wordit = WordItem(x); wdlst.insert(wdlst.begin(), wordit); return; } //... Find proper place and insert... return; }

The output of this program need to count each word alphabetically and the upper cases first . it should be like this eample.

Can you please help me complete this code: WordItem.h #ifndef WORDITEM_H #define

- C Microsoft Visual Studio Debug Console The: 1 a: 2 another: 1 began:1 boat:1 end: 1 for:1 from: 1 made: 1 newspaper:1 not: 1 of:1 sheet: 1 terror: 1 twenty-eight:1 which:1 with:1 would: 1 years:1 The most frequent word is 'a' with a count of 2

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!