Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 Day Apr 10, 2021

Solution

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

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

clean:
    rm $(TARGET)
stringset.cpp
#include "stringset.h"
constructor: an empty constructo
StringSet::StringSet() {}

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

constructor: a constructor that takes in a string vecto
uses the values inside vector to initialize the StringSet object.
StringSet::StringSet(vecto
string> a
)
{
int n = a
.size();
for(int i=0; i vecStore.push_back(a
.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
ool StringSet::isPresent(string str) const
{
bool found = false;
int n = vecStore.size();
for(int i=0; i if(vecStore.at(i) == str)
{
found = true;

eak;
}
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;

eak;
}
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