Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

THIS IS PROGRAM FOR C++ I'm given a list of programs: main.cpp main.h word.h list.h I'm supposed to make a list.cpp and a word.cpp that

THIS IS PROGRAM FOR C++

I'm given a list of programs:

main.cpp main.h word.h list.h

I'm supposed to make a list.cpp and a word.cpp that implements list.h and word.h. This is a word counting program that reads a text file and outputs:

Word "and" occurs 3 times Word "you" occurs 2 times Word "are" occurs 1 times

I have completed word.cpp but i'm having trouble with list.cpp. I will attach the source codes below.

You are only allowed to edit word.cpp and list.cpp

---------main.cpp---------

// Main definition file #include "main.h" using namespace std;

int main(int argc, char **argv) { List myList; fstream file;

// Try to open the input file if (argc < 2) { cerr << "?No input file provided" << endl; return 1; } else { file.open(argv[1],ios::in); // Open the file if (file.good() != true) { cerr << "?Unable to open \"" << argv[1] << "\"" << endl; return 1; } } // File is open. Read all words in the file file >> myList;

// Done with the file file.clear(); file.close();

// Display the word list cout << myList.size() << " words read" << endl; cout << myList << endl; return 0; }

----------main.h---------

// Header for main program #include #include #include #include

#include "word.h" #include "list.h"

-----------word.h--------

// Class Definition for Word class #pragma once #include #include

class Word { public: // Constructors Word(); // Default constructor Word(std::string); // Parameterized constructor Word(const Word &); // Copy constructor Word(Word &&); // Move constructor ~Word(); // Destructor

// Accessors std::string getWord(); // Accessor for word string int getCount(); // Accessor for count integer

// Mutators void setWord(std::string); // Mutator for word string void setCount(int); // Mutator for count

// Member Operators Word& operator++(); // Pre-increment: Change count Word operator++(int); // Post-increment: Change count Word& operator=(const Word &); // Copy assignment Word& operator=(Word&&); // Move assignment bool operator==(const Word &);// Relational bool operator<(const Word &); // Relational // Friends friend std::ostream & operator << (std::ostream &, const Word &); friend std::istream & operator >> (std::istream &, Word &);

private: std::string word; int count; };

---------word.cpp----------

#include "word.h"

//Constructors Word::Word() { count = 0; } Word::Word(std::string w) { word = w; count = 1; } Word::Word(const Word &w) { word = word.w; count = count.w; } Word::Word(Word &&w) { word = word.w; count = count.w; } //Destructor Word::~Word(); { //delete this; } //Accessors std::string Word::getWord() { return word; } int Word::getCount() { return count; } //Mutators void Word::setWord(std::string) { word = w; } void setCount(int c) { count = c; } //Member operators Word& Word::operator++() { ++count; return *this; } Word& Word::operator++(int) { Word old(*this) count++; return old; } Word& Word::operator=(const Word &w) { word = w.word; count = w.count; return *this; } Word& Word::operator=(const Word&& w) { word = w.word; count = w.count; return *this; } bool Word::operator==(const Word &other) { if(word == other.word) return true; else return false; } bool Word::operator<(const Word &other) { if(word < other.word) return true; else return false; } //Friends std::ostream & operator <<(std::ostream &out, const Word &w) { out << "Word \"" << w.word << "\" occurs " << w.count << " times"; return out; } std::istream & operator >>(std::istream &in, Word &w) { in >> w.word; w.count = 1; return in; }

---------list.h-------------

#include #include #include "word.h" #define max 10000

class List { public: List(); // Initialize ~List(); // Destruct bool append(Word); // Append to list int find(Word); // Find in list Word at(int); // Find in position int size(); // Size of list

friend std::ostream & operator << (std::ostream &, const List &); friend std::istream & operator >> (std::istream &, List &);

private: Word data[max]; // List int used; // Elements used int curr; // Current element };

------list.cpp------

This is where I need help. Please and thank you!!!!!!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions