Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ (n each of the operations, in comment form it states what each operation is

ID: 3787420 • Letter: C

Question

C++ (n each of the operations, in comment form it states what each operation is looking for and some of the implementations has already been started. Need help with finishing the rest of the implementation for each of the following operations below. Thank you.)

Implement the ListArray ADT [the declaration is given in ListArray.h, posted below]

Implement the following operations:

constructor, assignment operator, destructor

insert, remove, replace, clear

isFull, isEmpty

toBeginning, gotoEnd, gotoNext, gotoPrior, getCursor

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

#include "ListArray.h"

template < typename DataType >
List::List ( int maxNumber )
{

//needs implementation
}

template < typename DataType >
List::List ( const List& source )
{

//needs implementation


}
  
template < typename DataType >
List& List::operator= ( const List& source )
{
   return *this;
}

template < typename DataType >
List::~List ()
{
}

template < typename DataType >
void List::insert ( const DataType& newDataItem )
   throw ( logic_error )
{

/*

Inserts newDataItem after the cursor.

if ( size >= maxSize )

throw logic_error("list is full ");

for ( int j = size ; j > cursor+1 ; j-- )

dataItems[j] = dataItems[j-1];

Update size;

Update dataItems;

Update cursor;

*/


}

template < typename DataType >
void List::remove () throw ( logic_error )
{

/*

Check if the list is empty...;

for ( j = cursor ; j < size-1 ; j++ )

dataItems[j] = dataItems[j+1];

Update size;

Set the cursor

*/


}

template < typename DataType >
void List::replace ( const DataType& newDataItem )

throw ( logic_error )
{

// Replaces the item marked by the cursor with newDataItem


}

template < typename DataType >
void List::clear ()
{
}

template < typename DataType >
bool List::isEmpty () const
{
   return false;
}

template < typename DataType >
bool List::isFull () const
{
  /*

Returns true if a list is full. Otherwise, returns 0.

return ( size == maxSize );

*/


}

template < typename DataType >
void List::gotoBeginning ()
        throw ( logic_error )
{

/*

Moves the cursor to the beginning of the list.

Check if list is empty,...

cursor = 0;

*/


}

template < typename DataType >
void List::gotoEnd ()
        throw ( logic_error )
{
}

template < typename DataType >
bool List::gotoNext ()
        throw ( logic_error )
{

/*

If the cursor is not at the end of a list, then moves the

cursor to the next item in the list and returns true.

Check if list is empty

if ( cursor != size-1 )

{

Increase cursor;

...

}

else

...

*/


}

template < typename DataType >
bool List::gotoPrior ()
        throw ( logic_error )
{
   return false;
}

template < typename DataType >
DataType List::getCursor () const
        throw ( logic_error )
{

/*

Returns the item marked by the cursor.

Requires that the list is not empty.

return dataItems[cursor];

*/

}

#include "show3.cpp"

template < typename DataType >
void List::moveToNth ( int n )
        throw ( logic_error )
{
}

template < typename DataType >
bool List::find ( const DataType& searchDataItem )
        throw ( logic_error )
{
   /*

Begins the search from the cursor position.

Moves the cursor through the list until either searchDataItem

is found or the end of the list is reached.

while ( cursor < size && dataItems[cursor] !=searchDataItem )

Move forward;

if ( searchDataItem is found)

return true;

else

...

*/
}

template < typename DataType >
void List::gotoEnd ()
        throw ( logic_error )
{
}

template < typename DataType >
bool List::gotoNext ()
        throw ( logic_error )
{
   return false;
}

template < typename DataType >
bool List::gotoPrior ()
        throw ( logic_error )
{
   return false;
}

template < typename DataType >
DataType List::getCursor () const
        throw ( logic_error )
{
   DataType t;
   return t;
}

#include "show3.cpp"

template < typename DataType >
void List::moveToNth ( int n )
        throw ( logic_error )
{
}

template < typename DataType >
bool List::find ( const DataType& searchDataItem )
        throw ( logic_error )
{
   return false;
}

Explanation / Answer

#include "listArray.h" template List::List(int maxNumber) : maxSize(maxNumber), size(0), cursor(-1) { dataItems = new DataType[maxSize]; } template List::List(const List& source) : maxSize(source.maxSize), size(source.maxSize), cursor(source.cursor) { dataItems = new DataType[maxSize]; for (int i = 0; i maxSize = 0; x--) { dataItems[x] = 0; } size = 0; cursor = 0; } } template bool List::isEmpty() const { return (size == 0); } template bool List::isFull() const { return (size == maxSize); } template void List::gotoBeginning() throw (logic_error) { if (cursor != -1) { cursor = 0; } else { throw logic_error("Already at the beginning."); } } template void List::gotoEnd() throw (logic_error) { if (size != 0) { cursor = size - 1; } else { throw logic_error("Already at the end."); } } template bool List::gotoNext() throw (logic_error) { if (cursor == size) { throw logic_error("Cannot go to next, already at the end."); return false; } else if (cursor != size - 1) { cursor++; return true; } else { return false; } } template bool List::gotoPrior() throw (logic_error) { if (cursor == -1) { throw logic_error("Cannot go back, already at the beginning."); return false; } else { cursor--; return true; } } template DataType List::getCursor() const throw (logic_error) { if (cursor < 0) { throw ("Nothing to retrieve."); } else { return dataItems[cursor]; } } #include "show3.cpp" template void List::moveToNth(int n) throw (logic_error) { if (n > maxSize || n < 0) throw ("Out of Bounds."); else dataItems[n] = dataItems[cursor]; } template bool List::find(const DataType& searchDataItem) throw (logic_error) { for (int i = cursor; i