Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone help me complete this code. This is my Worditem.h #ifndef WORDITEM_H #define WORDITEM_H #include #include using namespace std; class WordItem { public: WordItem()

can someone help me complete this code.

This is my 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<<(ostream& os, const WordItem& wd) { os << wd.get_word()<<":"<

and this is the one i need help to complete main.cpp

#include #include #include "WordItem.h" #include

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("Harry_potter.txt"); inp >> next; next = strip_punct(next); while (!inp.fail()) { alpha_insert(next, wdList); // DEFINE BELOW inp >> next; next = strip_punct(next); // DEFINE BELOW } inp.close(); // Print out each word and its number of occurrence // in "Harry _potter _it"; word:count pair per alpha_insert // Iterate over the wdList and determine the word // among all WordItems that has maximal count; // : export this most frquent word and its count; return 0; }

template void print_list(list lst) { cout << endl; typename list::iterator itr; for (itr = lst.begin(); itr != lst.end(); ++itr) cout << *itr << " "; cout << endl; }

template void print_lines(list lst) { cout << endl; typename list::iterator itr; for (itr = lst.begin(); itr != lst.end(); ++itr) cout << *itr << " " << endl; cout << endl; }

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; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions