Define a class called StringSet that will be used to store a set of strings. Use a vector to store the strings. All strings in the set must be unique (i.e., no duplicates). Requirement: - constructor:...

1 answer below »

Define a class called StringSet that will be used to store a set of strings. Use a vector to store the strings. All strings in the set must be unique (i.e., no duplicates).   Requirement: - constructor: an empty constructor. - constructor: a constructor that takes in a string array (and its size), use the values inside array to initialize the StringSet object.  - constructor: a constructor that takes in a string vector, use the values inside vector to initialize the StringSet object. - member function: void add(string str), which adds str to the set.  - member function: void remove(string str), which removes str from the set.  - member function: void clear(), which clears all string sfrom the set.  - member function: int size(), which returns the count of number of strings in the set.  - member function: void union(const StringSet& ss), which unions with strings in ss.  - member function: void intersect(const StringSet& ss), which intersects with strings in ss.  - member function: void print(), which prints all strings in the set.  - main(): test all constructors and member functions in main().  - makefile: provide makefile for your solution - separate interface(.h) and implementation(.cpp)  File structures and names: - stringset.h: class StringSet interface - stringset.cpp: class StringSet implementation - test.cpp: contains main() and tests all constructors and member functions.  - makefile: contains compile instructions for make.   Grading:  - compilable and meaningfull attemps: 20% - StringSet class: 50% - test and main(): 20% - comment, indentation and file names and makefile: 10%


Answered Same DayApr 10, 2021

Answer To: Define a class called StringSet that will be used to store a set of strings. Use a vector to store...

Pritam answered on Apr 11 2021
149 Votes
makefile
CC = g++ #compiler
TARGET = test #target file name

all:
    $(CC) -w test.cpp stringset.cpp -o $(TARGET)

clean:
    rm $(TARGET)
stringset.cpp
#includ
e "stringset.h"
// constructor: an empty constructor
StringSet::StringSet() {}

// constructor: a constructor that takes in a string array (and its size)
// uses the values inside array to initialize the StringSet object
StringSet::StringSet(string *arr, int n)
{
for(int i=0; i vecStore.push_back(arr[i]);
}

// constructor: a constructor that takes in a string vector
// uses the values inside vector to initialize the StringSet object.
StringSet::StringSet(vector arr)
{
int n = arr.size();
for(int i=0; i vecStore.push_back(arr.at(i));
}
// member function: returns the string at index i in the set
string StringSet::getAt(int i) const
{
return vecStore.at(i);
}
// member function: checks whether str is present in the set
bool StringSet::isPresent(string str) const
{
bool found = false;
int n = vecStore.size();
for(int i=0; i if(vecStore.at(i) == str)
{
found = true;
break;
}
return found;
}
// member function: returns (unique) index where str is present in the set, -1 if not present
int StringSet::foundAt(string str) const
{
int found = -1;
int n = vecStore.size();
for(int i=0; i if(vecStore.at(i) == str)
{
found = i;
break;
}
return found;
}
    
// member function: adds str to the set
// in order to maintain uniqueness, adds only if str is not already present in set
void StringSet::add(string str)
{
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here