Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ only, Please have a StringSet.h and .cpp file. I also need a test.cpp file. Please also share screenshots of your code. Are you done

C++ only, Please have a StringSet.h and .cpp file. I also need a test.cpp file. Please also share screenshots of your code.

image text in transcribedimage text in transcribed

Are you done now?

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 StringSet Returning the intersection of the calling object and another StringSet Returning the set difference of the calling object and another StringSet 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 StringSet Methods You should implement each of the public methods described below. In each case you are given the method header which specifies the metho'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 0 StringSet(const StringSet &) 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 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 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) StringSet 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 StringSet 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 StringSet 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 StringSet Returning the intersection of the calling object and another StringSet Returning the set difference of the calling object and another StringSet 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 StringSet Methods You should implement each of the public methods described below. In each case you are given the method header which specifies the metho'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 0 StringSet(const StringSet &) 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 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 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) StringSet 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 StringSet 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 StringSet 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

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions