Learning Objectives: The objective of this lab is to gain experience working wit
ID: 3696909 • Letter: L
Question
Learning Objectives: The objective of this lab is to gain experience working with
linked list.
Assignment: Basic C++ program please write in basic c++ and nothing too advanced.
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 it
need not be sorted.
The IntegerSet class should have two data fields: the cardinality (size) of the set, and
the head reference to the linked list. It should provide the following public methods:
IntegerSet(int size): this constructor method creates a new set of size
integers by prompting the user to enter size elements for the set on the keyboard.
int size(): this method returns the cardinality of the set.
boolean isEmpty(): this method returns true if the set has no elements, false
otherwise.
boolean isMember(int item): this method returns true if item is an element of
the set, false otherwise.
boolean add(int item): if item is not in the set, this method adds it to the set
and returns true; otherwise, the set is unchanged and the method returns false.
boolean remove(int item): if item is in the set, this method removes it from
the set and returns true; otherwise, the set is unchanged and the method returns false.
boolean isSubset(IntegerSet set2): this method returns true if every
element in set2 is also in the calling set, false otherwise.
IntegerSet intersection(IntegerSet set2): this method returns a new
set that is the intersection of the calling set and set2. An integer is an element of the
intersection set if it is in both the calling set and set2.
IntegerSet union(IntegerSet set2): this method returns a new set that is
the union of the calling set and set2. An integer is an element of the union set if it is in
either the calling set or set2, or both. Keep in mind that the union set formed should
not contain any duplicates.
IntegerSet difference(IntegerSet set2): this method returns a new set
that is the difference between the calling set and set2 (in this order). An integer is an
element of the difference set if it is in the calling set but not in set2.
void display(): this method prints all elements of the set on the screen.
In addition to the IntegerSet class, you are also required to write a test driver that serves as
the test harness for the IntegerSet class. This test harness should provide the user with
options to explicitly test each method in the IntegerSet class.
Explanation / Answer
class IntegerSet{
int cordinality[5];
public:
integerSet(int size)
{
cordinality=size;
}
int size()
{ retun size}
boolean isEmpty()
{
for (i=0;i<5;i++)
{ if (cordinality[0]='')
return(1);
else
return(0)
}
}
boolean ismember()
{
for (i=0;i<5;i++)
{ if (item==cordinality[i])
return(1);
else return(0)
}}
boolean additem(int item)
{
for(int i=0;i<size;i++)
{
if (cordinality[i]=='')
{
cordinality[i]=item;
return(1)
else
return(0);
}
}}
boolean remove(int item)
{
for(int i=0;i<5;i++)
{
if (item==cordinality[i])
{
i++
return(1);
}
else
return(0);
}}
boolean issubset(integerset set2)
{
if(integerset Set1.size==integerset set2.size)
return(1);
else
return(0);
}
int integerset intersection(intergerset set2)
{
return (intergerset set1, intergerset set2);
}
int integerset union( integerset set2)
{
return(set.size, set2.size);
}
int integerset difference(integer set2)
{
return (set.size-set2.size);
}
}
void display()
{
cout<<cordinality;
cout<<size;
}
};
void main()
{
integerset set3;
set3(5);
set3.ismember(5)
set3.additem(6);
set3.remove();
set3.display();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.