Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hello, the question is to rewrite 2 files using templates...unorderedArrayListType.h..and unorederedsetType.h..I can always come up with main myself UNORDEREDARRAYLISTTYPE.H #ifndef H_unorderedArrayListType #define H_unorderedArrayListType #include #include

hello, the question is to rewrite 2 files using templates...unorderedArrayListType.h..and unorederedsetType.h..I can always come up with main myself

UNORDEREDARRAYLISTTYPE.H

#ifndef H_unorderedArrayListType

#define H_unorderedArrayListType

#include

#include "arrayListType.h"

using namespace std;

class unorderedArrayListType: public arrayListType

{

public:

virtual void insertAt(int location, int insertItem);

virtual void insertEnd(int insertItem);

virtual void replaceAt(int location, int repItem);

virtual int seqSearch(int searchItem) const;

virtual void remove(int removeItem);

unorderedArrayListType(int size = 100);

//Constructor

};

void unorderedArrayListType::insertAt(int location,

int insertItem)

{

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

cout << "The position of the item to be inserted "

<< "is out of range." << endl;

else if (length >= maxSize) //list is full

cout << "Cannot insert in a full list" << endl;

else

{

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

list[i] = list[i - 1]; //move the elements down

list[location] = insertItem;

length++; //increment the length

}

} //end insertAt

void unorderedArrayListType::insertEnd(int insertItem)

{

if (length >= maxSize) //the list is full

cout << "Cannot insert in a full list." << endl;

else

{

list[length] = insertItem; //insert the item at the end

length++; //increment the length

}

} //end insertEnd

int unorderedArrayListType::seqSearch(int searchItem) const

{

int loc;

bool found = false;

loc = 0;

while (loc < length && !found)

if (list[loc] == searchItem)

found = true;

else

loc++;

if (found)

return loc;

else

return -1;

} //end seqSearch

void unorderedArrayListType::remove(int removeItem)

{

int loc;

if (length == 0)

cout << "Cannot delete from an empty list." << endl;

else

{

loc = seqSearch(removeItem);

if (loc != -1)

removeAt(loc);

else

cout << "The item to be deleted is not in the list."

<< endl;

}

} //end remove

void unorderedArrayListType::replaceAt(int location, int repItem)

{

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

cout << "The location of the item to be "

<< "replaced is out of range." << endl;

else

list[location] = repItem;

} //end replaceAt

unorderedArrayListType::unorderedArrayListType(int size)

: arrayListType(size)

{

}

#endif

UNORDEREDSETTYPE.H

#ifndef H_unorderedSetType

#define H_unorderedSetType

#include

#include "unorderedArrayListType.h"

using namespace std;

class unorderedSetType: public unorderedArrayListType

{

public:

void insertAt(int location, int insertItem);

void insertEnd(int insertItem);

void replaceAt(int location, int repItem);

unorderedSetType(int size = 100);

//Constructor

};

void unorderedSetType::insertAt(int location,

int insertItem)

{

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

cout << "The position of the item to be inserted "

<< "is out of range." << endl;

else if (length >= maxSize) //list is full

cout << "Cannot insert in a full list" << endl;

else

{

int loc = seqSearch(insertItem);

if (loc == -1)

{

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

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

list[location] = insertItem;

length++;

}

else

cout << "The item to be inserted is already in the list." << endl;

}

} //end insertAt

void unorderedSetType::insertEnd(int insertItem)

{

if (length >= maxSize) //the list is full

cout << "Cannot insert in a full list." << endl;

else

{

int loc = seqSearch(insertItem);

if (loc == -1)

{

list[length] = insertItem;

length++; //increment the length

}

else

cout << "The item to be inserted is already in the list." << endl;

}

} //end insertEnd

void unorderedSetType::replaceAt(int location, int repItem)

{

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

cout << "The location of the item to be "

<< "replaced is out of range." << endl;

else

{

int loc = seqSearch(repItem);

if (loc == -1)

list[location] = repItem;

else

cout << "The item to be inserted is already in the list." << endl;

}

} //end replaceAt

unorderedSetType::unorderedSetType(int size)

: unorderedArrayListType(size)

{

} //end constructor

#endif

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

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago