Question
The code is required to be in C++ and I need an orderedArrayListTypeImp.cpp and a main.cpp. The following are the given code. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ arratListType.h: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The code is required to be in C++ and I need an orderedArrayListTypeImp.cpp and a main.cpp. The following are the given code.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arratListType.h:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include
#include "orderedArrayListType.h"
using namespace std;
void orderedArrayListType::insert(int insertItem)
{
if (length == 0)
list[length++] = insertItem;
else if (length == maxSize)
cout
else
{
int loc;
bool found = false;
for (loc = 0; loc
{
if (list[loc] >= insertItem)
{
found = true;
break;
}
}
for (int i = length; i > loc; i--)
list[i] = list[i - 1];
list[loc] = insertItem;
length++;
}
}
int orderedArrayListType::seqSearch(int searchItem) const
{
int loc;
bool found = false;
for (loc = 0; loc
{
if (list[loc] >= searchItem)
{
found = true;
break;
}
}
if (found)
{
if (list[loc] == searchItem)
return loc;
else
return -1;
}
else
return -1;
}
void orderedArrayListType::insertAt(int location, int insertItem)
{
if (location = maxSize)
cout
else if (length == maxSize)
cout
else
{
cout
insert(insertItem);
}
}
void orderedArrayListType::insertEnd(int insertItem)
{
if (length == maxSize)
cout
else
{
cout
insert(insertItem);
}
}
void orderedArrayListType::replaceAt(int location, int repItem)
{
if (location = length)
cout
else
{
removeAt(location);
insert(repItem);
}
}
void orderedArrayListType::remove(int removeItem)
{
int loc;
if (length == 0)
cout
else
{
loc = seqSearch(removeItem);
if (loc != -1)
removeAt(loc);
else
cout
}
}
orderedArrayListType::orderedArrayListType(int size): arrayListType(size)
{
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arrayListTypeImp.cpp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include
#include "arrayListType.h"
using namespace std;
bool arrayListType::isEmpty() const
{
return (length == 0);
} //end isEmpty
bool arrayListType::isFull() const
{
return (length == maxSize);
} //end isFull
int arrayListType::listSize() const
{
return length;
} //end listSize
int arrayListType::maxListSize() const
{
return maxSize;
} //end maxListSize
void arrayListType::print() const
{
for (int i = 0; i
cout
cout
} //end print
bool arrayListType::isItemAtEqual(int location, int item) const
{
if (location = length)
{
cout
return false;
}
else
return (list[location] == item);
} //end isItemAtEqual
void arrayListType::removeAt(int location)
{
if (location = length)
cout
else
{
for (int i = location; i
list[i] = list[i+1];
length--;
}
} //end removeAt
void arrayListType::retrieveAt(int location, int& retItem) const
{
if (location = length)
cout
else
retItem = list[location];
} //end retrieveAt
void arrayListType::clearList()
{
length = 0;
} //end clearList
arrayListType::arrayListType(int size)
{
if (size
{
cout
maxSize = 100;
}
else
maxSize = size;
length = 0;
list = new int[maxSize];
} //end constructor
arrayListType::~arrayListType()
{
delete [] list;
} //end destructor
arrayListType::arrayListType(const arrayListType& otherList)
{
maxSize = otherList.maxSize;
length = otherList.length;
list = new int[maxSize]; //create the array
for (int j = 0; j
list [j] = otherList.list[j];
}//end copy constructor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
orderedArrayListType.h
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifndef H_orderedArrayListType
#define H_orderedArrayListType
#include "arrayListType.h"
class orderedArrayListType: public arrayListType
{
public:
void insertAt(int location, int insertItem);
void insertEnd(int insertItem);
void replaceAt(int location, int repItem);
int seqSearch(int searchItem) const;
void insert(int insertItem);
void remove(int removeItem);
orderedArrayListType(int size = 100);
//Constructor
};
#endif
Write the definitions of the functions of the that are not given in this chapter. Also, write a program to test various operations of this class. Grading When you have completed your program, click the Submit button to record your score. Tasks orderedArrayListType 's method inserts an item into the specified position of the list. orderedArrayListType 's method inserts an item into the list. orderedArrayListType 's method inserts an item at the end of a list. orderedArrayListType 's method replaces an item at the specified position in the list. orderedArrayListType 's method returns 1 or the position of an element if found in the listStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started