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

*** Please make sure to use Visual Studio(C++). Thank you.** ListArray Class Des

ID: 3890305 • Letter: #

Question

*** Please make sure to use Visual Studio(C++). Thank you.**

ListArray Class

Description: You will implement your own List ADT, the ListArray class.

4.1. Implement default constructor: List<DataType>:: List (int maxNumber )

4.2. Implement copy constructor: List<DataType>:: List (const List &source)

4.3. Implement operator =: List<DataType>& List<DataType>::operator = ( const List &source)

4.4. Implement destructor: List<DataType>:: ~List ()

4.5. Implement insert (): void List<DataType>:: insert ( const DataType &newDataItem ) throw ( logic_error )

4.6. Implement remove (): void List<DataType>:: remove () throw (logic_error)

4.7. Implement replace (): void List<DataType>:: replace ( const DataType &newDataItem ) throw ( logic_error )

4.8. Implement clear (): void List<DataType>:: clear ()

4.9. Implement isEmpty():bool List<DataType>:: isEmpty () const

4.10. Implement isFull(): bool List<DataType>:: isFull () const

4.11. Implement gotoBeginning ():void List<DataType>:: gotoBeginning () throw ( logic_error )

4.12. Implement gotoEnd ():void List<DataType>:: gotoEnd () throw (logic_error )

4.13. Implement gotoNext ():void List<DataType>:: gotoNext () throw (logic_error )

4.14. Implement gotoPrior ():void List<DataType>:: gotoPrior () throw (logic_error )

4.15. Implement getCursor (): DataType List<DataType>:: getCursor () const throw ( logic_error )

4.16. Implement showStructure ():void List<DataType>:: showStructure ()const

7.1. Implement moveToNth ():void List:: moveToNth (int n ) throw ( logic_error )

7.2. Implement find ():bool List:: find (const DataType &searchDataItem ) throw ( logic_error )

#ifndef LISTARRAY_CPP

#define LISTARRAY_CPP

using namespace std;

#include <iostream>

#include <stdexcept>

#include "ListArray.h"

template < typename DataType >

List<DataType>::List ( int maxNumber )

// Creates an empty list. Allocates enough memory for maxNumber

// data items (defaults to defMaxListSize).

{

}

template < typename DataType >

List<DataType>::List ( const List& source )

// Copy constructor. Creates a deep-copy list copied from

// the provided model object, source.

{

}

  

template < typename DataType >

List<DataType>& List<DataType>::operator= ( const List& source )

// Overloaded assignment operator. Resets a list object to contain a

// deep-copy of the provided model object, source.

{

return *this;

}

template < typename DataType >

// Frees the memory used by a list.

List<DataType>::~List ()

{

}

template < typename DataType >

void List<DataType>::insert ( const DataType& newDataItem )

throw ( logic_error )

// Inserts newDataItem after the cursor. If the list is empty, then

// newDataItem is inserted as the first (and only) data items in the

// list. In either case, moves the cursor to newDataItem.

{

}

template < typename DataType >

void List<DataType>::remove () throw ( logic_error )

// Removes the data items marked by the cursor from a list. Moves the

// cursor to the next data item item in the list. Assumes that the

// first list data items "follows" the last list data item.

{

}

template < typename DataType >

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

throw ( logic_error )

// Replaces the item marked by the cursor with newDataItem and

// leaves the cursor at newDataItem.

{

}

template < typename DataType >

void List<DataType>::clear ()

// Removes all the data items from a list.

{

}

template < typename DataType >

bool List<DataType>::isEmpty () const

// Returns 1 if a list is empty. Otherwise, returns 0.

{

return false;

}

template < typename DataType >

bool List<DataType>::isFull () const

// Returns 1 if a list is full. Otherwise, returns 0.

{

return false;

}

template < typename DataType >

void List<DataType>::gotoBeginning ()

throw ( logic_error )

// Moves the cursor to the beginning of the list.

{

}

template < typename DataType >

void List<DataType>::gotoEnd ()

throw ( logic_error )

// Moves the cursor to the end of the list.

{

}

template < typename DataType >

bool List<DataType>::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. Otherwise,

// returns false.

{

return false;

}

template < typename DataType >

bool List<DataType>::gotoPrior ()

throw ( logic_error )

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

// cursor to the preceeding item in the list and returns true.

// Otherwise, returns false.

{

return false;

}

template < typename DataType >

DataType List<DataType>::getCursor () const

throw ( logic_error )

// Returns the item marked by the cursor.

{

DataType t;

return t;

}

#include "show3.cpp"

template < typename DataType >

void List<DataType>::moveToNth ( int n )

throw ( logic_error )

// Removes the data item marked by the cursor from a list and

// reinserts it as the nth data item in the list -- where the

// data items are numbered from beginning to end, starting with 0.

// Moves the cursor to the new position of the moved data

// item.

{

}

template < typename DataType >

bool List<DataType>::find ( const DataType& searchDataItem )

throw ( logic_error )

// Searches a list for searchDataItem. Begins the search with the

// data items marked by the cursor. Moves the cursor through the list

// until either searchDataItem is found (returns true) or the end of the

// list is reached (returns false).

{

return false;

}

#endif // ifndef LISTARRAY_CPP

Explanation / Answer

Below is youir implementation

#ifndef LISTARRAY_CPP

#define LISTARRAY_CPP

# include "ListArray.h"

template < typename DataType >

List<DataType>::List ( int maxNumber)

{

maxSize = maxNumber;

cursor = -1;

size =0;

dataItems = new DataType[maxSize];

}

template < typename DataType >

List<DataType>::List( const List& source )

{

maxSize = source.maxSize;

size = source.size;

cursor = source.cursor;

dataItems = new DataType[maxSize];

for (int i=0;i<size;i++)

dataItems[i] = source.dataItems[i];

}

template < typename DataType >

List<DataType>& List<DataType> ::operator= ( const List& source )

{

if (this!= & source)

{

delete [] dataItems;

maxSize = source.maxSize;

size = source.size;

cursor = source.cursor;

dataItems = new DataType[maxSize];

for (int i=0;i<size;i++)

dataItems[i] = source.dataItems[i];

}

return *this;

}

template < typename DataType >

List<DataType>::~List ()

{

delete [] dataItems;

}

template < typename DataType >

void List<DataType>:: insert ( const DataType& newDataItem )

{

if (isFull())

throw logic_error("List is full");

else

{

size++;

if (cursor==-1)

{

cursor=0;

}

else

{

for (int i=size-2;i>cursor;i--)

dataItems[i+1]=dataItems[i];

cursor++;

}

dataItems[cursor]= newDataItem;

}

}

template < typename DataType >

void List<DataType>::remove () throw ( logic_error )

{

if (isEmpty())

throw logic_error("List is empty");

else

{

if (cursor == size-1)

{

size--;

gotoBeginning();

}

else

{

for (int i = cursor;i<size;i++)

{

dataItems[i]=dataItems[i+1];

}

size--;

}

}

}

template < typename DataType >

void List<DataType>::replace ( const DataType& newDataItem ) throw ( logic_error )

{

if (isEmpty())

throw logic_error("List is empty");

else

dataItems[cursor]=newDataItem;

}

template < typename DataType >

void List<DataType>::clear ()

{

size = 0;

cursor = -1;

}

template < typename DataType >

bool List<DataType>::isEmpty () const

{

if (size ==0)

return true;

return false;

}

template < typename DataType >

bool List<DataType>::isFull () const

{

if (size == maxSize)

return true;

return false;

}

template < typename DataType >

void List<DataType>::gotoBeginning () throw ( logic_error )

{

if (isEmpty())

throw logic_error("list is empty");

else cursor = 0;

}

template < typename DataType >

void List<DataType>::gotoEnd () throw ( logic_error )

{

if (isEmpty())

throw logic_error("list is empty");

else cursor = size-1;

}

template < typename DataType >

bool List<DataType>::gotoNext () throw ( logic_error )

{

if (isEmpty())

throw logic_error("list is empty");

else

{

if (cursor<size-1)

{

cursor++;

return true;

}

}

return false;

}

template < typename DataType >

bool List<DataType>::gotoPrior () throw ( logic_error )

{

if (isEmpty())

throw logic_error("list is empty");

else

{

if (cursor!=0)

{

cursor--;

return true;

}

}

return false;

}

template < typename DataType >

DataType List<DataType>::getCursor ()const throw ( logic_error )

{

if (isEmpty())

throw logic_error("list is empty");

else

return dataItems[cursor];

}

template < typename DataType >

void List<DataType>::showStructure () const

{

int j; // loop counter

if ( size == 0 )

cout << "empty list" << endl;

else

{

cout << "size = " << size

<< " cursor = " << cursor << endl;

for ( j = 0 ; j < maxSize ; j++ )

cout << j << " ";

cout << endl;

for ( j = 0 ; j < size ; j++ ) {

if( j == cursor ) {

cout << "[";

cout << dataItems[j]

#ifdef ORDEREDLIST_CPP

.getKey()

#endif

;

cout << "]";

cout << " ";

}

else

cout << dataItems[j]

#ifdef ORDEREDLIST_CPP

.getKey()

#endif

<< " ";

}

cout << endl;

}

}

template < typename DataType >

void List<DataType>::moveToNth ( int n ) throw ( logic_error )

{

if (size<n+1)

throw logic_error("list does not have enough data items");

else

{

DataType temp;

temp = getCursor();

remove();

gotoBeginning();

if (n==0)

{

size++;

for (int i=size-1;i>=cursor;i--)

dataItems[i+1]=dataItems[i];

dataItems[0]=temp;

}

else

{

for (int i=0;i<n-1;i++)

gotoNext();

insert(temp);

}

}

}

template < typename DataType >

bool List<DataType>::find ( const DataType& searchDataItem ) throw ( logic_error )

{

  

if (isEmpty())

throw logic_error("list is empty");

else

{

for (int i = cursor;i<size;i++)

{

if (dataItems[i]==searchDataItem)

{

cursor = i;

return true;

}

}

cursor = size-1;

}

return false;

  

}

# endif