Question
In C++ please help, thank you so much Your main task is to implement all the functions declared in the interface,the main file is already
In C++ please help, thank you so much
Your main task is to implement all the functions declared in the interface,the main file is already written. You can tackle these tasks in the following stages:
1. Note that a 0-argument constructor creating an empty set is already implemented for you inline. Implement a 1-argument constructor to open a text file and populate the data array with up to CAPACITY distinct words in the order that they appear in the file, keeping track of the number of distinct words in size . Because the file may have duplicate words, it is possible for it to have more tokens than the capacity of a lexicon but for it to not fill a lexicon. For example, if you have a file hello.txt with CAPACITY instances of "hello" followed by one instance of "world", then calling Lexicon lex("hellofile.txt") from main should result in an object lex where lex.data is an array whose first two entries are"hello"and"world"andlex.size is2. However, if there are more than CAPACITY distinct values in your file, your constructor should fill the data array with the first CAPACITY distinct values and ignore the rest of the file.
2. Implement three boolean member functions contains , insert , and remove consistent with the pre- and post-conditions stipulated in the header file.
3. Overload three bitwise operators as member functions so that lex1 | lex2 corresponds to the union of the two lexicons(i.e.,any string in either or both of the underlying lexicons), lex1 & lex2 corresponds to the intersection of the two lexicons (i.e., any string in both of the underlying lexicons), and lex1 lex2 corresponds to the symmetric difference of the two lexicons(i.e.,any string that appears in exactly one not both of the two underlying lexicons).
Note that because each of these operators is implemented as a member function, the function is written with lex1 as the reference object and lex2 as a single parameter, and the function constructs, populates, and returns a third lexicon object.
4. Overload six comparison operators as nonmember functions with the following functionality:
lex1 == lex2 is true if and only if every string in one of the lexicons is also in the other (though not necessarily in the same position),
lex1 != lex2 is true if and only if the reissome string in one lexicon and not the other, lex1
lex1
lex1 >= lex2 is true if and only if the second lexicon is a subset of the first,and lex1 > lex2 is true if and only if these cond lexicon is a strict subset of the first.
Note that because each of these operators is implemented as a nonmember function, the contents of the parameters can only be accessed through public functions such as [], which is implemented for you, and contains, which you will have implemented in Step 2.
lexicon.h:
// Interface file
#ifndef LEXICON_H #define LEXICON_H
#include #include #include using std::string; using std::ostream; using std::ifstream;
class Lexicon { public:
// STATIC CONSTANT
static const size_t CAPACITY = 2000;
// CONSTRUCTORS
// Pre: N/A // Post: An empty (size 0) lexicon is created Lexicon() : size_(0) {}
// Pre: A text file called filename is in the current directory // Post: A lexicon w/ the file's first CAPACITY distinct strings is created Lexicon(string filename);
// CONSTANT ACCESSOR MEMBER FUNCTIONS
// Pre: N/A // Post: The number of elements stored is returned size_t size() const { return size_; }
// Pre: N/A // Post: The truth value of whether the word is in the lexicon is returned bool contains(string word) const;
// Pre: This object has at least pos+1 elements // Post: The element at index pos is returned string operator [](size_t pos) const { return data_[pos]; }
// MUTATOR MEMBER FUNCTIONS
// Pre: N/A // Post: The word is added to the end of the lexicon and true is returned // if word was distinct and there was space; false is returned otherwise bool insert(string word);
// Pre: N/A // Post: If the word was present, it is removed and true is returned; // false is returned otherwise bool remove(string word);
// SET OPERATOR OVERLOADS
// Pre: N/A // Post: A union lexicon is constructed, populated with the first CAPACITY // distinct elements of this object and rhs, and returned Lexicon operator |(const Lexicon& rhs) const;
// Pre: N/A // Post: An intersection lexicon is constructed, populated with the elements // common to this object and rhs, and returned Lexicon operator &(const Lexicon& rhs) const;
// Pre: N/A // Post: A symmetric difference lexicon is constructed, populated with // the first CAPACITY elements of this object XOR rhs, and returned Lexicon operator ^(const Lexicon& rhs) const;
private:
// INVARIANTS: data_[0],...,data_[size_-1] always contain the elements
string data_[CAPACITY]; size_t size_;
};
// INSERTION OPERATOR OVERLOAD
// Pre: N/A // Post: Space-separated in-order contents of lex are inserted in out ostream& operator
// COMPARISON OPERATOR OVERLOADS
// Pre: N/A // Post: True is returned iff the contents of lhs and rhs are identical bool operator ==(const Lexicon& lhs, const Lexicon& rhs);
// Pre: N/A // Post: True is returned iff the contents of lhs and rhs are not identical bool operator !=(const Lexicon& lhs, const Lexicon& rhs);
// Pre: N/A // Post: True is returned iff the every lhs element is in rhs bool operator
// Pre: N/A // Post: True is returned iff every lhs element is in rhs which is not identical bool operator
// Pre: N/A // Post: True is returned iff the every rhs element is in lhs bool operator >=(const Lexicon& lhs, const Lexicon& rhs);
// Pre: N/A // Post: True is returned iff every rhs element is in lhs which is not identical bool operator >(const Lexicon& lhs, const Lexicon& rhs);
#endif
lexicon.cpp - -/Desktop/hw3 lexicon.cpp lexicon.h main.cpp // Implementation starter file for CSCI 60 Homework 3; due Sunday 1/24/21 // List any collaborators and write your name here #include "lexicon.h" /* TODO: implement the other functions declared in lexicon.h here */ 11 12 13 14 15 16 // Inserts contents of lex in out in order, separated by spaces ostream& operatorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started