Get in touch with us
Send us an e-mail
Question
Implement the following Set class. A set is a collection of items with no duplicates. The following class implements a set of integers.
#ifndef SET_H
#define SET_H
#include <iostream>
#include <vector>
using namespace std;
class Set
{
// friend operator functions
friend ostream &operator<<(ostream & out, const Set & s);
friend istream &operator>>(istream & in, Set & s);
public:
// Constructors
Set(); // default constructor
Set(const Set & s); // copy constructor
// destructor
~Set();
// operator functions
Set operator||(Set & s); // union of the set with the set s
Set operator&&(Set & s); // intersection of the set with the set s
const Set& operator=(const Set & s); // assignment
bool operator==(const Set & s); // equality
int& operator[](int index); // returns modifiable lvalue
int operator[](int index) const; // returns rvalue
// Set membership functions
bool member(int m); // The integer m is a member
void add(int m); // add the integer m to the set
void remove(int m); // remove the integer m from the set
private:
vector<int> _s;
};
#endif
The member functions must be written in a file Set.cpp. Now consider which can contain duplicate items. Thus a Set is a Bag but not vice versa in general. Design a polymorphic class hierarchy for Sets and Bags. The header file for the Set class in this hierarchy must be given in Set.h and the header file for Bag class must be given in Bag.h. Provide the implementation files Set.cpp and Bag.cpp.. The following are some examples of Bag intersection (), and Bag union ().∩∪
{1,2,2,2,3,3}{1,1,2,2,3} = {1,2,2,3} ∩
{1,2,2,2,3,3}{1,1,2,2,3} = {1,1,2,2,2,3,3}∪
You must clearly identify which member functions must be virtual
Summary
The question belongs to Computer Science and it discusses about designing a polymorphic class hierarchy for sets and bags.
Total Word Count NA
The concepts surrounding kinetics and dynamics in chemical engineering often confused me in my initial days, till I came across HwA. Their team of online chemical engineering assignment experts helped me through the course by letting me get excellent grades in all of my assignments. And the best part is that because the tutors are from Singapore itself there is no gap in the communication between us.
I was stuck with my fault detection in logic circuit assignment when I looked up in the net for help. Luckily I came across HwA and it was all so quick. Within 5 minutes of me enquiring for help, they mailed me back letting me know about the process. The assignment went well and since then I always consult HwA for any of my assignments.
I was having a lot of difficulty managing all the assignments that we needed to complete for my post graduate program in Financial Accounting. When I needed to write an accounting assignment essay on cash flow statement I really did not have the time to do all the research and then write the assignment. With the New Zealand accounting assignment expert at HwA I did not have to worry one bit for my assignment writing and scored an A in it.
The nursing expert of HwA has actually cleared by idea about gastrointestinal anatomy and helped me in several occasions with critical case study solutions involving gastrointestinal issues of the patients.
It is important to have a constant guide while you do your dissertation as the lack of constant help often leaves you all the more bewildered. The New Zealand dissertation expert who helped me with my assignment was available on a constant basis and she helped me get a fantastic grade.
Comments
this is a very good website
I have 50 questions for the same test your page is showing only 28
hi can you please help or guide me to answer my assignments. thanks
hi can anyone help or guide me to my assignments. thanks
This solution is perfect ...thanks
Hello Allison,I love the 2nd image that you did! I also, had never heard of SumoPaint, is something that I will have to exolpre a bit! I understand completely the 52 (or so) youtube videos that you probably watched. Sometimes they have what you want, sometimes they don't! However, it is always satisfying when you are able to produce something that you have taught yourself. Great job!Debra 0 likes
Perfect bank of solution.
great !
thanks for the quick response. the solution looks good. :)
thnx for the answer. it was perfect. just the way i wanted it.
works fine.