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

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

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 should be look like this exmple:

image text in transcribed

- 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

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

More Books

Students also viewed these Databases questions

Question

Express your approval for a well-done job on a daily basis.

Answered: 1 week ago