Starting from:
$35

$29

Programming Project #2 Solution

Part 1 A NameSet is an unordered group of unique items. You are to code a NameSet class according to the following specification. For this class, you are to code the NameSet class to derives from the Bag class provided (similar to Bag class presented in Chapter 3). That is, the NameSet class is to be a public inheritance from the Bag class which is provided. You are NOT to make ANY changes to the Bag class.




NameSet ADT

This class represents a NameSet of names, each name being a string object. All names stored in this object are UNIQUE.




Effect: constructor to create a NameSet which can store CAPACITY elements

Precondition: NONE

Postcondition: an empty NameSet object exists

NameSet::NameSet()




Effect: Determines if this NameSet is empty

Precondition: NONE

Postcondition: this NameSet object is unchanged

Returns: true if this NameSet is empty, false otherwise

bool NameSet::isEmpty() const




Effect: Determines if this NameSet is full

Precondition: NONE

Postcondition: this NameSet object is unchanged

Returns: true if this NameSet is full, false otherwise

bool NameSet::isFull() const




Effect: inserts newItem into the NameSet

Precondition: this NameSet is not full

Postcondition: if newItem was not contained in the set then newItem has been added to the set and true was returned, otherwise false was returned

bool NameSet::insert(const string& newItem)




Effect: inserts newItem into the NameSet

Precondition: this NameSet is not full

Postcondition: if newItem was not contained in the set then newItem has been stored at the front of the set, with other items moved down and true returned, else false returned

bool NameSet::insertFirst(const string& newItem)




Effect: first item in the NameSet is removed

Precondition: the NameSet is not empty

Postcondition: a value has been removed from this NameSet

Returns: the string which was removed from the set

string NameSet::eraseFirst()










Effect: determines if a value is contained in the NameSet

Precondition: NONE

Postcondition: this NameSet object is unchanged

Returns: returns true if this NameSet contains ‘item’, otherwise false is returned

bool NameSet::isThere(const string& item) const

Effect: creates a NameSet that is the intersection of two NameSet objects

Precondition: None

Postcondition: both NameSet parameters are unchanged

Returns: returns a NameSet object which contains elements which are contained in BOTH set1

and set2

static NameSet NameSet::intersect(const NameSet& set1, const NameSet& set2)




Effect: determines if two NameSets are equal

Precondition: NONE

Postcondition: this NameSet object is unchanged

Returns: returns true if this NameSet contains the same elements as in aNameSet

(storage order is not important for equality)

bool NameSet::operator==(const NameSet& aNameSet) const




Effect: compares the length of two NameSets

Precondition: NONE

Postcondition: this NameSet object is unchanged

Returns: returns true if this NameSet contains more names than aNameSet

bool NameSet::operator(const NameSet& aNameSet) const




Effect:outputs the elements of this NameSet in format { int, int, int, etc }

If NameSet is empty, { } is output

Returns: the ostream object that was passed in as a parameter

friend ostream& operator<< (ostream& out, const NameSet& obj)




Part 2

Write an interactive application which will manipulate two NameSets. Your application must creates two NameSet objects and allow the user of the program to perform any of the following options until the user wishes to exit:




* add a name to NameSet1 (user provides name)

* add a name to NameSet2 (user provides name)

* remove a specific name from NameSet1 (user provides name)

* remove the first name from NameSet1

* allow the user to search NameSet1 for a particular name (user provides name)

* output names that are included in both NameSet1 and NameSet2

* output a message indicating if NameSet1 contains more names than NameSet2

* output a message stating if the two NameSet’s are equal or not




YOUR program should output both NameSets following EACH operation.




Note that there are some functions that are not explicitly called. Your application will be using some of these functions to verify preconditions. Be sure and test your program with a variety of input values, making sure that all of your functions work correctly in all cases (attempt at duplicate entries, attempt to add/remove from full/empty NameSets, etc).




You are to submit three files only, NameSet.h, NameSet.cpp and your main application .cpp file. Submit these as email attachments. I will verify that I have received the submission within 24 hours with a thank you email.

More products