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
Code :
StringSet.h
#include<iostream>
using namespace std;
class StringSet{
string set[100];
public:
StringSet();
StringSet(String[],int);
StringSet(vector<StringSet>);
void add(String);
void remove(String);
void clear();
int size();
void union(StringSet);
void intersect(StringSet);
void print();
};
StringSet.cpp
#include<iostream>
#include<StringSet.h>
using namespace std;
StringSet::StringSet()
{
}
StringSet::StringSet(String a[],int n)
{
set=a;
}
void StringSet::add(String s1);
{
for(int i=0;i<set.length();i++);
strcpy(set[i],s1);
}
void StringSet::remove(String s1)
{
for(int i=0;i<set.length();i++)
{
if(strcmp(set[i],s1)==0)
{
for(int j=i;j<set.length();j++)
{
strcpy(set[j],set[j+1]);
}
}
}
}
void StringSet::clear()
{
for(int i=0;i<set.length;i++)
free(set[i]);
}
int StringSet::size()
{
return set.length();
}
void StringSet::print()
{
for(int i=0;i<Set.length();i++)
printf("%s\n",set[i]);
}
main.cpp
#include<iostream>
#include<StringSet.cpp>
using namespace std;
int main()
{
string set1[100]={'ABC','EFG','GHI','JKL','MNO'};
StringSet StringSetObj;
StringSetObj(set1,100);
StringSetObj.add('zk');
StringSetObj.print();
StringSetObj.remove('MNO');
StringSetObj.size();
StringSetObj.clear();
return 0;
}
makefile
proc CODE=cpp CPP_SUFFIX=cpp PARSE=NONE
main.o : main.cpp
g++ -o main.o main.cpp
StringSet.o : StringSet.cpp
g++ -o StringSet.o StringSet.cpp
output : main.o StringSet.o
g++ -O output
Define a class called StringSet that will be used to store a set of strings. Use...