Question

How do I fix my error of binding on line 74? #include <iostream> #include <fstream> #include...

How do I fix my error of binding on line 74?

#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <iomanip>
using namespace std;
#include "AvlTree.h"
class WordCount
{
public:
    char *word;
    int *lines;
    int count;
    int size;
    bool operator<(const WordCount &rhs) const {return strcmp(word, rhs.word) < 0;}
    bool operator!= (const WordCount &rhs) const {return strcmp(word, rhs.word) != 0;}
    WordCount():lines(NULL), count(0), size(0) {word = new char[1]; word[0] = '\0';}
    friend ostream& operator<< (ostream &os, const WordCount &rhs);
    WordCount& operator= (const WordCount &rhs)
    {
      if(this == &rhs)
        return *this;
    
      delete[] word;
      word = new char[strlen(rhs.word) + 1];
      strcpy(word, rhs.word);
      delete[] lines;
      lines = new int[rhs.size];
      for(int i = 0; i < rhs.count; i++)
        lines[i] = rhs.lines[i];
      
      count = rhs.count;
      size = rhs.size;
    
      return *this;
    } // operator=
};

ostream& operator<< (ostream &os, const WordCount &rhs)
{
os << setw(18) << left << rhs.word << rhs.count << "   ";
for(int i = 0; i < rhs.count - 1; i++)
    os << rhs.lines[i] << ',';

os << rhs.lines[rhs.count - 1];
return os;
}


void readFile(const char *filename, AvlTree <WordCount> &tree)
{
int lineCount = 1;
char *ptr, *ptr2, line[10000];
WordCount word, word2;
word2.word = new char[10000];
ifstream inf(filename);

while(inf.getline(line, 10000))
{
    for(ptr = line; *ptr && !isalpha(*ptr); ptr++);
  
    while(*ptr)
    {
    
      for(ptr2 = ptr; isalpha(*ptr2); ptr2++)
        *ptr2 = tolower(*ptr2);
    
      char temp = *ptr2;
      *ptr2 = '\0';
    
      if(strlen(ptr) > 0)
      {
        strcpy(word2.word, ptr);
        WordCount &tempWord = tree.find(word2);
      
        if(tempWord.word[0] != '\0')
        {
          if(tempWord.count == tempWord.size)
          {
            int *tempLine = new int[tempWord.size * 2];
          
            for(int i = 0; i < tempWord.count; i++)
              tempLine[i] = tempWord.lines[i];
          
            delete [] tempWord.lines;
            tempWord.lines = tempLine;
            tempWord.size *= 2;
          } // if we need to resize the lines
        
          tempWord.lines[tempWord.count++] = lineCount;
        }
        else // word not in tree
        {
          word.word = new char[strlen(ptr) + 1];
          strcpy(word.word, ptr);
          word.lines = new int[10];
          word.count = 1;
          word.size = 10;
          word.lines[0] = lineCount;
          tree.insert(word);
        }
      
      } // if a real word
      
      *ptr2 = temp;
      for(ptr = ptr2; *ptr && !isalpha(*ptr); ptr++);
    
    } // while more in line
  
    lineCount++;
} // while more lines
} // readFile()


int main(int argc, char** argv)
{
WordCount word;
AvlTree <WordCount> tree(word);
readFile(argv[1], tree);
tree.printTree();
return 0;
} // main())

Homework Answers

Answer #1

#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <iomanip>
using namespace std;
#include "AvlTree.h"
class WordCount
{
public:
    char *word;
    int *lines;
    int count;
    int size;
    bool operator<(const WordCount &rhs) const {return strcmp(word, rhs.word) < 0;}
    bool operator!= (const WordCount &rhs) const {return strcmp(word, rhs.word) != 0;}
    WordCount():lines(NULL), count(0), size(0) {word = new char[1]; word[0] = '\0';}
    friend ostream& operator<< (ostream &os, const WordCount &rhs);
    WordCount& operator= (const WordCount &rhs)
    {
      if(this == &rhs)
        return *this;
    
      delete[] word;
      word = new char[strlen(rhs.word) + 1];
      strcpy(word, rhs.word);
      delete[] lines;
      lines = new int[rhs.size];
      for(int i = 0; i < rhs.count; i++)
        lines[i] = rhs.lines[i];
      
      count = rhs.count;
      size = rhs.size;
    
      return *this;
    } // operator=
};

ostream& operator<< (ostream &os, const WordCount &rhs)
{
os << setw(18) << left << rhs.word << rhs.count << "   ";
for(int i = 0; i < rhs.count - 1; i++)
    os << rhs.lines[i] << ',';

os << rhs.lines[rhs.count - 1];
return os;
}


void readFile(const char *filename, AvlTree <WordCount> &tree)
{
int lineCount = 1;
char *ptr, *ptr2, line[10000];
WordCount word, word2;
word2.word = new char[10000];
ifstream inf(filename);

while(inf.getline(line, 10000))
{
    for(ptr = line; *ptr && !isalpha(*ptr); ptr++);
  
    while(*ptr)
    {
    
      for(ptr2 = ptr; isalpha(*ptr2); ptr2++)
        *ptr2 = tolower(*ptr2);
    
      char temp = *ptr2;
      *ptr2 = '\0';
    
      if(strlen(ptr) > 0)
      {
        strcpy(word2.word, ptr);
        WordCount &tempWord = tree.find(word2);
      
        if(tempWord.word[0]!= '\0')
        {
          if(tempWord.count == tempWord.size)
          {
            int *tempLine = new int[tempWord.size * 2];
          
            for(int i=0; i< tempWord.count; i++)
              tempLine[i] = tempWord.lines[i];
          
            delete[] tempWord.lines;
            tempWord.lines = tempLine;
            tempWord.size *= 2;
          } // if we need to resize the lines
        
          tempWord.lines[tempWord.count++] = lineCount;
        }
        else // word not in tree
        {
          word.word = new char[strlen(ptr) + 1];
          strcpy(word.word, ptr);
          word.lines = new int[10];
          word.count = 1;
          word.size = 10;
          word.lines[0] = lineCount;
          tree.insert(word);
        }
      
      } // if a real word
      
      *ptr2 = temp;
      for(ptr = ptr2; *ptr && !isalpha(*ptr); ptr++);
    
    } // while more in line
  
    lineCount++;
} // while more lines
} // readFile()


int main(int argc, char** argv)
{
WordCount word;
AvlTree <WordCount> tree(word);
readFile(argv[1], tree);
tree.printTree();
return 0;
} // main())

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix it.. Can you explain to me what I am doing wrong? Warning: dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:66:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:93:8: error: invalid operands of types 'dlist::node*' and 'dlist::node*' to binary 'operator+' dlist.cc:97:8: error: could not convert 'result' from 'int' to 'dlist' My code:...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
For each part labeled P(n), there is a warning/error/problem that goes with it. Write down what...
For each part labeled P(n), there is a warning/error/problem that goes with it. Write down what the issue was in the `Error:` section of each problem. And fix the code to make it work. // P0 #include <stdio.h> #include <stdlib.h> /* Error: */ void fib(int* A, int n); int main(int argc, char *argv[]) { int buf[10]; unsigned int i; char *str; char *printThisOne; char *word; int *integers; int foo; int *bar; char *someText; // P1 for (i = 0; i...
IN C PROGRAMMING A Tv_show structure keeps track of a tv show’s name and the channels...
IN C PROGRAMMING A Tv_show structure keeps track of a tv show’s name and the channels (integer values) that broadcast the show. For this problem you can ONLY use the following string library functions: strcpy, strlen, strcmp. You MAY not use memcpy, memset, memmove. You can assume memory allocations are successful (you do not need to check values returned by malloc nor calloc). typedef struct tv_show { char *name; int num_channels, *channels; } Tv_show; a. Implement the init_tv_show function that...
Description The word bank system maintains all words in a text file named words.txt. Each line...
Description The word bank system maintains all words in a text file named words.txt. Each line in the text file stores a word while all words are kept in an ascending order. You may assume that the word length is less than 20. The system should support the following three functions: Word lookup: to check whether a given word exists in the word bank. Word insertion: to insert a new word into the word bank. No insertion should be made...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT