Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class in C++ called Set that can hold 100 positive integer numbers from 0-99. You may implement this as an array or vector

Write a class in C++ called Set that can hold 100 positive integer numbers from 0-99.

You may implement this as an array or vector of boolean elements.

Add constructor(s), and the following methods:

1. void add( int i ) // add the number i to the set.

2. bool belongs(int i) // return true if i is a member of the set

3. void difference( Set B) // removes B from the set A where A is the current set so A= A-B

4. void union(Set B)// performs A U B // where A is the current set and the result is stored in A

5. void intersect (Set B) // performs A image text in transcribed B // where A is the current set and the result is stored in A

6. string toString() //displays the set in roster notation {1,2,4} etc.

Write a client that instantiates two sets A and B. A = {2,4,6,8,10} B = {1,2,3,4}

Perform the operations in this order and call (Please include output statements before each call to explain your call as follows)

1. A.toString() //printing A

2. B.toString() //printing B

3. A.add(12) // adding 12 to A

4. A.toString() //printing A

5. A.belongs(4) // does 4 belong to A

6. A.belongs(11) // does 11 belong to A

7. A.difference(B) // remove B from A

8. A.toString() //printing A

9. A.union(B) // union of A and B

10. A.toString() // printing A

11 A.intersect(B) // intersecting A and B

12.A.toString()// printing A

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

=+21.16. For the density Cexp( -1x| "), - o Answered: 1 week ago

Answered: 1 week ago