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

Additional Information:

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

Reference no: EM13829602

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

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Use html5 to create a document that contains

Insert a horizontal rule between the h1 element and the p element. Open your new document in a web browser to view the marked up document.

  Develop monthly claim status summary report

Dr. Jones has asked you to develop a monthly Claim Status Summary report. He wishes you to write the insurance company number, patient number and name.

  List out some ways to improve the interaction design

List out some ways to improve the interaction design of the poor web site.(must be at least 70 words long)

  Ipo chart its components and benefits to program development

Discuss the IPO chart, its components, and its benefits to program development. In your opinion, what would be the impact if one of these components were omitted? Thoroughly explain.

  Which dim statement would correctly declare an array

Which Dim statement would correctly declare an array of this structure for elements having subscripts from 0 through 30

  Write an essay on turing machine explain with examples

Write an essay on turing machine explain with examples

  Customer driven analytics to make managerial decisions

Demonstrate your understanding and knowledge gained about session's material. Complete with a short discussion (one paragraph) for each question on a Word document and upload through the courseware.

  Will everything eventually be ethernet / csma/cd

Is Ethernet that good that it's the predominant form of LAN? Will everything eventually be Ethernet / CSMA/CD?

  What is the global cpi for each implementation?

Given a program with a dynamic instruction count of 1.0E6 instructions divided into classes as follows: 10% class A, 20% class B, 50% class C, and 20% class D, which implementation is faster?"

  Check whether relation is boyce-codd normal form

Consider a relation R(A, B, C, D, E, F), with FDs AB → C , BC → D, D → E, BE → F and DF → C.

  Identify performance bottlenecks in a particular system

Windows Experience Index, under Windows Vista/7, is a summary index designed to measure the overall performance of a system. You can use it to compare systems and identify performance bottlenecks in a particular system. Discuss its base score conc..

  Computing new computer cost at the end of year

Assume that 5 years from now you would like to trade in the computer and purchase a new one. You expect at 5 % increase in price each year. What would the new computer cost at the end of year 5?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd