Question

Please give an answer which works to print the answer given below. Please use the necessary header .h and .cpp files. Please give the right solution. "ITS MY HUMBLE REQUEST TO GIVE THE RIGHT SOLUTION"

Question 2 – Creating and working with other Containers

A Set is a data structure which contains information on whether a value belongs to

that set or not. In this question, you have to implement an integer Set which is able

to tell whether an integer is a member of that Set or not. For this question our set

can only contain the numbers 0..9. Because our list of possible members is small we

can represent the Set by a Boolean map where we have an array, called content,

with 10 elements. If the integer i is in the set then content[i] is true, otherwise it is

false. Thus if the set contains the number 3 then content[3] is true. If the set doesn’t

contain the number 8 then content[8] is false. In this question, our set starts out

empty - it contains no members.

Create a Set class in Set.cpp and Set.h implement the following functions:

Constructor – makes the set empty by setting all elements of content to false.

add(int val) – ensures that the set contains element val by setting the

corresponding element of content to true. If val is outside the range of 0..9

remove(int val) – ensures that the set does not contain the element val. If val

is outside the range 0..9 then val does nothing.

in(int val) returns true if val is in the set and false otherwise. If val is outside

the range 0..9 then in() returns false.

With the correct implementation of the class file above the q2main.cpp file

should print:

members

1 is member

3 is member

5 is member

7 is member

members

2 is member

4 is member

7 is member

8 is member

/*
C++ program that demonstrates the Set class methods
*/

//main.c
#include<iostream>
#include "Set.h"
using namespace std;
int main()
{

//Create a Set class object
Set set;

cout<<"members"<<endl;
//print only set elements
for(int index=0;index<10;index++)
if(set.in(index))
cout<<index<<" is member"<<endl;

//Create a Set class object
Set set2;
cout<<"members"<<endl;
//print only set elements
for(int index=0;index<10;index++)
if(set2.in(index))
cout<<index<<" is member"<<endl;

//pause program output on console
system("pause");
return 0;
}

--------------------------------------------------------------------------------------------------

//Set.h
#ifndef SET_H
#define SET_H
//Class Set declaration
class Set
{
private:
//an array of boolean type of size,10
bool contents[10];
public:
//constructor
Set();
//Methods
void remove(int val);
bool in(int val);
};
#endif SET_H

--------------------------------------------------------------------------------------------------

//Set.cpp

//Implementation file
#include<iostream>
#include "Set.h"
//Constructor to false to all contents array
Set::Set()
{
int index=0;
for(index=0;index<10;index++)
contents[index]=false;
}
//add method to set val to the corresponding value in contents array
{
if(val>=0 && val<10)
contents[val]=true;
}
//remove method to set val false to the corresponding value in contents array
void Set::remove(int val)
{
if(val>=0 && val<10)
contents[val]=false;
}
//in method that returns true if the val is in the set otherwise return false
bool Set::in(int val)
{
if(val>=0 && val<10)
{
if(contents[val])
return true;
else
return false;
}
}

--------------------------------------------------------------------------------------------------

Sample Output:

#### Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
• ### Intro to java project template with instructions below * IntegerSet.java */ /** * * @author StudentName...

Intro to java project template with instructions below * IntegerSet.java */ /** * * @author StudentName */ public class IntegerSet {    /** * Creates a new instance of IntegerSet    */ // TODO: implement the constructor    /** * Return a new IntegerSet containing the union of the two IntegerSet objects * passed as arguments */ // TODO: implement the union method    /** * Return a new IntegerSet containing the intersection of the two IntegerSet objects * passed...

• ### I want solution for this question

(IntegerSet Class) Create class IntegerSet for which each object can hold integers in the range 0 through 100. Represent the set internally as a vector of bool values.Element a[i] is true if integer i is in the set. Element a[j] is false if integer j is not in the set. The default constructor initializes a set to the so-called“empty set,” i.e., a set for which all elements contain false. Provide member functions for the common set operations. For example, provide...

• ### c++ Please create Set.cpp and Set.h The following information is needed (setinterface.h) Class Set You are...

c++ Please create Set.cpp and Set.h The following information is needed (setinterface.h) Class Set You are given an interface: SetInterfac This is a public interface and completely specifies what the Set class operations must be. SetInterface is an abstract class (it has no implementation), so your Set class must inherit from SetInterface and implement all of its methods. Set differs in the fact that it does not allow duplicates. This also means that add()must check that an element is not...

//Look for** to complete this program --C+ please --please add comments // using namespace std; #include <iostream> #include <stdlib.h> #include < string> #include "queue.h" //Purpose of the program: ** Algorithm: * int main() /** "A", "B", "C" in the queue //** while loop -- indefinitely { try {//** catches } //* end of loop } |/ II II II II II //File type: ** queue.cpp using namespace std; #include <iostream> #include "queue.h" // constructor queue::queue () } //destructor queue::~queue() queue::queue...

• ### Write the C module intSet to implement an unordered set of integers according to the specification...

Write the C module intSet to implement an unordered set of integers according to the specification given below. File intSet.h (downloadable off the class web pages): #ifndef INTSET_H #define INTSET_H typedef struct intsetType *intSet; intSet createSet(); // returns an intSet created at runtime using malloc void destroySet(intSet); // frees up the memory associated with its argument void clear(intSet); // clears set to empty (freeing any memory if necessary) int card(const intSet); // returns the cardinality of the set bool equals(const...

• ### can i please get help on this? i don't know how to do it and I'm...

can i please get help on this? i don't know how to do it and I'm so confused. This is in java. This is what I need to do. Thank you so much. In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node) , but...

• ### 117% Question 1: Linked Lists Create an IntLinkedList class, much like the one presented in class....

117% Question 1: Linked Lists Create an IntLinkedList class, much like the one presented in class. It should implement a linked list that will hold values of type int. It should use an IntNode class to implement the nodes in the linked list. The linked list must have the following methods: . A constructor with no parameters which creates an empty list. . void add (int data) -adds data to the front of the list. .A constructor IntlinkedList(int[]) which will...

• ### 5. Below i s the class deciaration for the Bag class from your text. Refer to...

5. Below i s the class deciaration for the Bag class from your text. Refer to this hea he Ted implementation @file Bag.h #ifndet BAG #define BAG template <class ItemType> class Bag private: static const int DEFAULT BAG SIZE 6; Il current count of Bag items /I max capacity of the Bag ItemType items[DEFAULT BAG SIZE]; //array of Bag items int itemCount; int maxitems; /l Returns either the index of the element in the array items that ll contains the...

• ### Complete the implementation of the LinkedStack class presented in Chapter 13. Specifically, complete the implementations of...

Complete the implementation of the LinkedStack class presented in Chapter 13. Specifically, complete the implementations of the peek, isEmpty, size, and toString methods. See Base_A06Q1.java for a starting place and a description of these methods. Here is the base given: /** * Write a description of the program here. * * @author Lewis et al., (your name) * @version (program version) */ import java.util.Iterator; public class Base_A06Q1 { /** * Program entry point for stack testing. * @param args Argument...

• ### C++ how to program. EX:10.9

Create class IntegerSet for which each object can hold integers inthe range 0 through 100. Represent the set internally as a privatedata member, which is a vectorof bool values. Element a[ i ] istrue if integer i is in the set. Element a[ j ] is false if integerj is not in the set. The default constructor initializes a settothe so-called "empty set," i.e., a set for which all elementscontain false.Provide member functions for the common set operations. Forexample, provide...