Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++, need StringSet.h and StringSet.cpp. I need a test file aswell here is my implementation so far StringSet.h using namespace std; #include #include class StringSet

image text in transcribedimage text in transcribed

C++, need StringSet.h and StringSet.cpp. I need a test file aswell

here is my implementation so far

StringSet.h

using namespace std; #include  #include  class StringSet { public: // Constructor and destructor // constructor that creates an array of strings of size 2 in dynamic memory, // setsmaximum size to 2, and current size to 0 StringSet(); // copy constructor that creates a deep copy of its parameter StringSet(const StringSet &); // destructor that frees dynamic memory associated with the objects string //(array) pointer ~StringSet(); // overloaded assignment operator that creates a deep copy of its parameter, // assigns it to the calling object, deallocates any no longer required // dynamic memory associated with the calling object; this method should check // for self assignment as discussed in class StringSet & operator=(const StringSet & string); //Returns false if stirng already in arra, otherwise inserts into /ext available index, otherwise doubles size, copies, frees old, //then inserts parameter, increments sixze, and returns true bool inset(string); //if a string matching param in array, returns index of string, else -1 int find(string); //returns the current size (the number of strings in the array) int size() const; //returns a StringSet object that contains the union of the calling //object and the parameter (if the result is the empty set the //returned StringSet objects current size should equal zero); //in case you were wondering, this method is called unions because //union is a reserved word StringSet unions(const StringSet &) const; //returns a StringSet object that contains the intersection of the //calling object and the parameter StringSet intersection(const StringSet &) const; //returns a StringSet object that contains the set difference of //the calling object and the parameter StringSet difference(const StringSet &) const; private: //the string "array" string* arr; // the size of the array int maxSize; //the currentsize of the array int curSize; };

StringSet.cpp

using namespace std; #include  #include  #include "StringSet.h" // Default constructor // POST: Creates an StringSet object with an array of size 2 // PARAM: StringSet::StringSet() { maxSize = 2; arr = new string[currSize]; currSize = 0; } //Coppy Constructor //PRE: //POST: copies array of the calling object //PARAM: str string to be copied StringSet::StringSet(const StringSet & str) { maxSize = str.maxSize; curSize = str.curSize; // Make a new array arr = new string[maxSize]; // Copy content of parameter for(int i=0; i   CMPT 225 Assignment 1 - String Set You are to implement a class that stores a set of strings. The class should use a dynamic array as its underlying representation. This assignment is worth 5% of your grade. Please read the requirements carefully, paying particular attention to the names and input and output requirements of the class and its methods. We will be testing your class in our test program, so if you do not follow the requirements the program may not compile. Assignment submissions that do not compile will not be marked. We will be compiling and running our test program and your class in Linux using the g++ compiler with the -std=C++11 option. If you complete your assignment in some other environment (such as Visual Studio) I would strongly suggest checking that it compiles in g++ before submitting it. String Set Class Class Description Your class should be named StringSet and should support these operations:  Creating an empty set  Inserting a string . Removing a string . Finding a string  Returning the size of a set  Returning the union of the calling object and another String Set . Returning the intersection of the calling object and another String Set  Returning the set difference of the calling object and another String Set Class Attributes Your class should be implemented using a dynamic array and should have at least the following private member variables  A pointer to a string that will point to an array of strings created in dynamic memory . An int that records the current size of the array (i.e. the number of strings stored in the array) . An int that records the maximum size of the array String Support Your header file should include the string class (#include ). The string class is part of the standard namespace (std). Class Files Your class should consist of a header file called StringSet.h that contains the class definition and an implementation file called StringSet.cpp that contains the method definitions String Set Methods You should implement each of the public methods described below. In each case you are given the method header which specifies the method's name, return type and parameter list. A brief description follows each method, including any exceptions that should be thrown by the method. You may implement other private methods as you deem necessary. Methods  StringSet() - constructor that creates an array of strings of size 2 in dynamic memory, sets maximum size to 2, and current size to O StringSet(const String Set &)- copy constructor that creates a deep copy of its parameter ~StringSet() - destructor that frees dynamic memory associated with the object's string (array) pointer StringSet & operator= (const String Set &)- overloaded assignment operator that creates a deep copy of its parameter, assigns it to the calling object, deallocates any no longer required dynamic memory associated with the calling object; this method should check for self assignment as discussed in class bool insert(string) - returns false without inserting value if a string matching the parameter is already in the array, otherwise: inserts the string parameter at the next available index; if the underlying array is full, doubles the maximum size attribute, creates an array of twice the size of the current array, copies the contents of the old array to the new array, frees memory associated with the old array, and assigns new array's address to object's array pointer, then inserts parameter; increments current size and returns true bool remove(string)  returns false if a string matching the parameter is not in the array, otherwise: replaces matching string with the last string in the array (if there is one); decrements current size and returns true int find(string) const - if a string matching the parameter is in the array returns the index of that string, otherwise returns -1 int size() const - returns the current size (the number of strings in the array) String Set unions(const StringSet &) const - returns a StringSet object that contains the union of the calling object and the parameter (if the result is the empty set the returned String Set object's current size should equal zero); in case you were wondering, this method is called unions because union is a reserved word StringSet intersection(const StringSet &) const - returns a StringSet object that contains the intersection of the calling object and the parameter StringSet difference(const StringSet &) const - returns a String Set object that contains the set difference of the calling object and the parameter  CMPT 225 Assignment 1 - String Set You are to implement a class that stores a set of strings. The class should use a dynamic array as its underlying representation. This assignment is worth 5% of your grade. Please read the requirements carefully, paying particular attention to the names and input and output requirements of the class and its methods. We will be testing your class in our test program, so if you do not follow the requirements the program may not compile. Assignment submissions that do not compile will not be marked. We will be compiling and running our test program and your class in Linux using the g++ compiler with the -std=C++11 option. If you complete your assignment in some other environment (such as Visual Studio) I would strongly suggest checking that it compiles in g++ before submitting it. String Set Class Class Description Your class should be named StringSet and should support these operations:  Creating an empty set  Inserting a string . Removing a string . Finding a string  Returning the size of a set  Returning the union of the calling object and another String Set . Returning the intersection of the calling object and another String Set  Returning the set difference of the calling object and another String Set Class Attributes Your class should be implemented using a dynamic array and should have at least the following private member variables  A pointer to a string that will point to an array of strings created in dynamic memory . An int that records the current size of the array (i.e. the number of strings stored in the array) . An int that records the maximum size of the array String Support Your header file should include the string class (#include ). The string class is part of the standard namespace (std). Class Files Your class should consist of a header file called StringSet.h that contains the class definition and an implementation file called StringSet.cpp that contains the method definitions String Set Methods You should implement each of the public methods described below. In each case you are given the method header which specifies the method's name, return type and parameter list. A brief description follows each method, including any exceptions that should be thrown by the method. You may implement other private methods as you deem necessary. Methods  StringSet() - constructor that creates an array of strings of size 2 in dynamic memory, sets maximum size to 2, and current size to O StringSet(const String Set &)- copy constructor that creates a deep copy of its parameter ~StringSet() - destructor that frees dynamic memory associated with the object's string (array) pointer StringSet & operator= (const String Set &)- overloaded assignment operator that creates a deep copy of its parameter, assigns it to the calling object, deallocates any no longer required dynamic memory associated with the calling object; this method should check for self assignment as discussed in class bool insert(string) - returns false without inserting value if a string matching the parameter is already in the array, otherwise: inserts the string parameter at the next available index; if the underlying array is full, doubles the maximum size attribute, creates an array of twice the size of the current array, copies the contents of the old array to the new array, frees memory associated with the old array, and assigns new array's address to object's array pointer, then inserts parameter; increments current size and returns true bool remove(string)  returns false if a string matching the parameter is not in the array, otherwise: replaces matching string with the last string in the array (if there is one); decrements current size and returns true int find(string) const - if a string matching the parameter is in the array returns the index of that string, otherwise returns -1 int size() const - returns the current size (the number of strings in the array) String Set unions(const StringSet &) const - returns a StringSet object that contains the union of the calling object and the parameter (if the result is the empty set the returned String Set object's current size should equal zero); in case you were wondering, this method is called unions because union is a reserved word StringSet intersection(const StringSet &) const - returns a StringSet object that contains the intersection of the calling object and the parameter StringSet difference(const StringSet &) const - returns a String Set object that contains the set difference of the calling object and the parameter

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_2

Step: 3

blur-text-image_3

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions