Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions Unordered Sets |As explained in this chapter, a set is a collection of distinct elements of the same type. Design the class unorderedSetType, derived

Instructions

Unordered Sets |As explained in this chapter, a set is a collection of distinct elements of the same type. Design the class unorderedSetType, derived from the class unorderedArrayListType, to manipulate sets.

Note that you need to redefine only the functions insertAt, insertEnd, and replaceAt. If the item to be inserted is already in the list, the functions insertAt and insertEnd output an appropriate message, such as 13 is already in the set. Similarly, if the item to be replaced is already in the list, the function replaceAt outputs an appropriate message. Also, write a program to test your class.

Expected outcome:

1

input:

2 3 4 9 12 15 95 54 4 13

Output:

2 3 9 12 15 95 54

13 is not in intList

2

input:

58 85 74 95 62 51 4 999 999 999

Output:

58 85 74 95 62 51 4

999 is not in intList

Classes:

arrayListType.h:

#ifndefH_arrayListType

#defineH_arrayListType

classarrayListType

{

public:

boolisEmpty()const;

//Functiontodeterminewhetherthelistisempty

//Postcondition:Returnstrueifthelistisempty;

//otherwise,returnsfalse.

boolisFull()const;

//Functiontodeterminewhetherthelistisfull

//Postcondition:Returnstrueifthelistisfull;

//otherwise,returnsfalse.

intlistSize()const;

//Functiontodeterminethenumberofelementsin

//thelist.

//Postcondition:Returnsthevalueoflength.

intmaxListSize()const;

//Functiontodeterminethemaximumsizeofthelist

//Postcondition:ReturnsthevalueofmaxSize.

voidprint()const;

//Functiontooutputtheelementsofthelist

//Postcondition:Elementsofthelistareoutputonthe

//standardoutputdevice.

boolisItemAtEqual(intlocation,intitem)const;

//Functiontodeterminewhetheritemisthesameas

//theiteminthelistatthepositionspecified

//bylocation.

//Postcondition:Returnstrueiflist[location]

//isthesameasitem;otherwise,

//returnsfalse.

//Iflocationisoutofrange,an

//appropriatemessageisdisplayed.

virtualvoidinsertAt(intlocation,intinsertItem)=0;

//FunctiontoinsertinsertIteminthelistatthe

//positionspecifiedbylocation.

//Notethatthisisanabstractfunction.

//Postcondition:Startingatlocation,theelementsof

//thelistareshifteddown,

//list[location]=insertItem;length++;

//Ifthelistisfullorlocationisoutof

//range,anappropriatemessageisdisplayed.

virtualvoidinsertEnd(intinsertItem)=0;

//FunctiontoinsertinsertItemattheendof

//thelist.Notethatthisisanabstractfunction.

//Postcondition:list[length]=insertItem;andlength++;

//Ifthelistisfull,anappropriate

//messageisdisplayed.

voidremoveAt(intlocation);

//Functiontoremovetheitemfromthelistatthe

//positionspecifiedbylocation

//Postcondition:Thelistelementatlist[location]is

//removedandlengthisdecrementedby1.

//Iflocationisoutofrange,an

//appropriatemessageisdisplayed.

voidretrieveAt(intlocation,int&retItem)const;

//Functiontoretrievetheelementfromthelistatthe

//positionspecifiedbylocation

//Postcondition:retItem=list[location]

//Iflocationisoutofrange,an

//appropriatemessageisdisplayed.

virtualvoidreplaceAt(intlocation,intrepItem)=0;

//Functiontoreplacetheelementsinthelist

//atthepositionspecifiedbylocation.

//Notethatthisisanabstractfunction.

//Postcondition:list[location]=repItem

//Iflocationisoutofrange,an

//appropriatemessageisdisplayed.

voidclearList();

//Functiontoremovealltheelementsfromthelist

//Afterthisoperation,thesizeofthelistiszero.

//Postcondition:length=0;

virtualintseqSearch(intsearchItem)const=0;

//FunctiontosearchthelistforsearchItem.

//Notethatthisisanabstractfunction.

//Postcondition:Iftheitemisfound,returnsthe

//locationinthearraywheretheitemis

//found;otherwise,returns-1.

virtualvoidremove(intremoveItem)=0;

//FunctiontoremoveremoveItemfromthelist.

//Notethatthisisanabstractfunction.

//Postcondition:IfremoveItemisfoundinthelist,

//itisremovedfromthelistandlength

//isdecrementedbyone.

arrayListType(intsize=100);

//Constructor

//Createsanarrayofthesizespecifiedbythe

//parametersize.Thedefaultarraysizeis100.

//Postcondition:Thelistpointstothearray,length=0,

//andmaxSize=size;

arrayListType(constarrayListType&otherList);

//Copyconstructor

virtual~arrayListType();

//Destructor

//Deallocatethememoryoccupiedbythearray.

protected:

int*list; //arraytoholdthelistelements

intlength; //variabletostorethelengthofthelist

intmaxSize; //variabletostorethemaximum

//sizeofthelist

};

#endif

arrayListTypeImp.cpp:

#include

#include"arrayListType.h"

usingnamespacestd;

boolarrayListType::isEmpty()const

{

return(length==0);

}//endisEmpty

boolarrayListType::isFull()const

{

return(length==maxSize);

}//endisFull

intarrayListType::listSize()const

{

returnlength;

}//endlistSize

intarrayListType::maxListSize()const

{

returnmaxSize;

}//endmaxListSize

voidarrayListType::print()const

{

for(inti=0;i

cout<

cout<

}//endprint

boolarrayListType::isItemAtEqual(intlocation,intitem) const

{

if(location<0||location>=length)

{

cout<<"Thelocationoftheitemtoberemoved"

<<"isoutofrange."<

returnfalse;

}

else

return(list[location]==item);

}//endisItemAtEqual

voidarrayListType::removeAt(intlocation)

{

if(location<0||location>=length)

cout<<"Thelocationoftheitemtoberemoved"

<<"isoutofrange."<

else

{

for(inti=location;i

list[i]=list[i+1];

length--;

}

}//endremoveAt

voidarrayListType::retrieveAt(intlocation,int&retItem)const

{

if(location<0||location>=length)

cout<<"Thelocationoftheitemtoberetrievedis"

<<"outofrange"<

else

retItem=list[location];

}//endretrieveAt

voidarrayListType::clearList()

{

length=0;

}//endclearList

arrayListType::arrayListType(intsize)

{

if(size<=0)

{

cout<<"Thearraysizemustbepositive.Creating"

<<"anarrayofthesize100."<

maxSize=100;

}

else

maxSize=size;

length=0;

list=newint[maxSize];

}//endconstructor

arrayListType::~arrayListType()

{

delete[]list;

}//enddestructor

arrayListType::arrayListType(constarrayListType&otherList)

{

maxSize=otherList.maxSize;

length=otherList.length;

list=newint[maxSize]; //createthearray

for(intj=0;j

list[j]=otherList.list[j];

}//endcopyconstructor

main.cpp:

//Data:184278224254257

#include

#include"unorderedSetType.h"

usingnamespacestd;

intmain(){

//Writeyourmainhere

return0;

}

unorderedArrayListType.h:

#ifndefH_unorderedArrayListType

#defineH_unorderedArrayListType

#include"arrayListType.h"

classunorderedArrayListType:publicarrayListType

{

public:

virtualvoidinsertAt(intlocation,intinsertItem);

virtualvoidinsertEnd(intinsertItem);

virtualvoidreplaceAt(intlocation,intrepItem);

virtualintseqSearch(intsearchItem)const;

virtualvoidremove(intremoveItem);

unorderedArrayListType(intsize=100);

//Constructor

};

#endif

unorderedArrayListTypeImp.cpp:

#include

#include"unorderedArrayListType.h"

usingnamespacestd;

voidunorderedArrayListType::insertAt(intlocation,

intinsertItem)

{

if(location<0||location>=maxSize)

cout<<"Thepositionoftheitemtobeinserted"

<<"isoutofrange."<

elseif(length>=maxSize) //listisfull

cout<<"Cannotinsertinafulllist"<

else

{

for(inti=length;i>location;i--)

list[i]=list[i-1]; //movetheelementsdown

list[location]=insertItem;//inserttheitemat

//thespecifiedposition

length++;//incrementthelength

}

}//endinsertAt

voidunorderedArrayListType::insertEnd(intinsertItem)

{

if(length>=maxSize) //thelistisfull

cout<<"Cannotinsertinafulllist."<

else

{

list[length]=insertItem;//inserttheitemattheend

length++;//incrementthelength

}

}//endinsertEnd

intunorderedArrayListType::seqSearch(intsearchItem)const

{

intloc;

boolfound=false;

loc=0;

while(loc

if(list[loc]==searchItem)

found=true;

else

loc++;

if(found)

returnloc;

else

return-1;

}//endseqSearch

voidunorderedArrayListType::remove(intremoveItem)

{

intloc;

if(length==0)

cout<<"Cannotdeletefromanemptylist."<

else

{

loc=seqSearch(removeItem);

if(loc!=-1)

removeAt(loc);

else

cout<<"Theitemtobedeletedisnotinthelist."

<

}

}//endremove

voidunorderedArrayListType::replaceAt(intlocation,intrepItem)

{

if(location<0||location>=length)

cout<<"Thelocationoftheitemtobe"

<<"replacedisoutofrange."<

else

list[location]=repItem;

}//endreplaceAt

unorderedArrayListType::unorderedArrayListType(intsize)

:arrayListType(size)

{

} //endconstructor

unorderedSetType.h:

#ifndefH_unorderedSetType

#defineH_unorderedSetType

#include"unorderedArrayListType.h"

classunorderedSetType:publicunorderedArrayListType

{

public:

voidinsertAt(intlocation,intinsertItem);

voidinsertEnd(intinsertItem);

voidreplaceAt(intlocation,intrepItem);

unorderedSetType(intsize=100);

//Constructor

};

#endif

unorderedSetTypeImp.cpp:

Nothing

I need unorderedSetTypeImp.cpp and main.cpp

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Programming questions

Question

=+2. What are the two ways govemment can finance a budget deficit?

Answered: 1 week ago

Question

Figure 2.57 10 Ecological Footprint

Answered: 1 week ago