Polymorphic class hierarchy for sets and bags

Assignment Help Basic Computer Science
Reference no: EM13829602

Problem:

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 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

This question is from Computer Science as well as it explains about designing the polymorphic class hierarchy for sets and bags.

Questions Cloud

 Statement review the dictum that truth always triumphs : Statement review the dictum that truth always triumphs Java game development jump it : The game "Jump It" consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board with n set to 6: Write an essay on copying of computer software : The problem is belongs to Sociology and the problem is describe about writing an essay on copying of computer software and its de-criminalization. What are the internal rates of return for the projects : what are the internal rates of return for the following projects? Polymorphic class hierarchy for sets and bags : Implement the following Set class. A set is a collection of items with no duplicates. The following class implements a set of integers. What means do you use to develop supporting ideas : Is there a time of day when you're more effective? Do you prefer working in isolation or in the company of others? Are you more productive composing at a keyboard or with pen and paper? Net present value calculation-internal rate of return : (Net present value calculation) Big Steve’s, makers of swizzle sticks, is considering the purchase of a new plastic stamping machine. This investment requires an initial outlay of \$100,000 and will generate net cash inflows of \$18,000 per year for 10.. Statement review the unquestionable property of the labourer : Statement Review the unquestionable property of the labourer Differences between cash flow and accounting income : Discuss differences between cash flow and accounting income and why it is important to use cash flow in making capital budgeting decisions. How do companies generate ideas for capital projects? Give some examples of capital projects that companies in..

Write a Review

What is the server IP address

Use Wireshark tool to capture packets when you download Lecture 1 from the COIT20229 Course Webpage. Before you undertake this task, you should have Wireshark installed in your home computer/notebook and connected to the Internet.

Winter and spring and displays the total

Write a visual logic program for an application that allows a user to enter the cost of home maintenance in each of the four seasons summer, fall, winter and spring and displays the total.

What is a predefined control event

What is a predefined control event? Discuss its usage in programming

Explain the means of investigating trademark

Discuss and explain the means of investigating trademark and copyright infringement, sexual harassment incidents, and child pornography and laws concerning those incidents.

Create queue class should have the following methods

create queue class should have the following methods:

The medical biller

A physician has treated a patient who has a diagnosis that is not listed on the superbill. How is this handled by the physician? The medical biller?

Imagine that you are trying to receive funding for select planning projects. Compare and contrast the attributes of business continuity and disaster recovery plans, and suggest the primary ways in which you would explain these differences to your emp..

Differences and similarities of the business models

Recognize differences and similarities of the business models, taking into account the following factors: Who is the target audience for this Web site.

Elastic and inelastic traffic

Outline a plan for the development of an addressing and naming model in an environment of the following scenario:

Dns is a commonly used service in the internet

1> DNS is a commonly used service in the Internet. Explain the roles of the local name servers, the authoritative name servers, and the root name servers.

Webflix maintains customer data in a 2d-array

WebFlix maintains customer data in a 2D-array called WF. Where the rows correspond to the customers and the columns correspond to films that it rents. An entry WF[i,j] indicates the number of times a customer has rented a film.WebFlix wants to find s..

What are some business uses for inserting a canvas

Write a response that answers the following: What are some business uses for inserting a canvas in a Microsoft® Word document. From these uses, propose a strategy that may help users overcome formatting issues.