Respuesta :
To add the function max as an abstract function to the class arraylisttype to return the largest element of the list, check the code given below.
What is element?
A smaller component of a larger system is referred to as an element in computing.
//CODE//
#include <iostream>
using namespace std;
class arrayListType
{
public:
bool isEmpty() const;
bool isFull() const;
int listSize() const;
int maxListSize() const;
void print() const;
bool isItemAtEqual(int location, int item) const;
virtual void insertAt(int location, int insertItem) = 0;
//F
virtual void insertEnd(int insertItem) = 0;
void removeAt(int location);
void retrieveAt(int location, int& retItem) const;
virtual void replaceAt(int location, int repItem) = 0;
void clearList();
virtual int seqSearch(int searchItem) const = 0;
virtual void remove(int removeItem) = 0;
virtual int max() = 0;
arrayListType(int size = 100);
arrayListType(const arrayListType& otherList);
virtual ~arrayListType();
protected:
int *list; //array to hold the list elements
int length; //variable to store the length of the list
int maxSize; //variable to store the maximum
//size of the list
};
#endif
//UNORDEREDARRAYLIST:
#ifndef H_unorderedArrayListType
#define H_unorderedArrayListType
#include "arrayListType.h"
arrayListType::arrayListType(int size)
{
list = new int[size];
length = 0;
maxSize = size;
}
arrayListType::arrayListType(const arrayListType& otherList)
{
if (list)
delete[] list;
list = new int[otherList.maxSize];
length = otherList.length;
for (int i = 0;i < length;i++)
{
list[i] = otherList.list[i];
}
}
arrayListType::~arrayListType()
{
if (list)
delete[] list;
list = nullptr;
}
void arrayListType::clearList()
{
for (int i = 0;i < length;i++)
list[i] = 0;
length = 0;
}
void arrayListType::removeAt(int location)
{
for (int i = location;i < length - 1;i++)
{
list[i] = list[i + 1];
}
length--;
}
void arrayListType::retrieveAt(int location, int& retItem) const
{
if (location >= length)
return;
retItem = list[location];
}
bool arrayListType::isEmpty() const
{
return length == 0;
}
bool arrayListType::isFull() const
{
return (length == maxSize);
}
int arrayListType::listSize() const
{
return length;
}
int arrayListType::maxListSize() const
{
return maxSize;
}
void arrayListType::print() const
{
cout << endl;
for (int i = 0;i < length;i++)
cout << list[i] << " ";
}
bool arrayListType::isItemAtEqual(int location, int item) const
{
if (location >= length)
return false;
return list[location] == item;
}
class unorderedArrayListType : 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 remove(int removeItem);
// Add the function max
int max();
unorderedArrayListType(int size = 100);
//Constructor
};
#endif
//UNODERERD ARRAYLISTLMP :
#include <iostream>
#include "unorderedArrayListType.h"
using namespace std;
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; //insert the item at
//the specified position
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
// Add the definition for the function max
int unorderedArrayListType::max()
{
int maxValue = INT_MIN;
for (int i = 0;i < length;i++)
{
if (list[i] > maxValue)
maxValue = list[i];
}
return maxValue;
}
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)
{
} //end constructor
int main()
{
unorderedArrayListType list;
list.insertEnd(1);
list.insertEnd(-1);
list.insertEnd(10);
list.insertEnd(2);
list.insertEnd(5);
cout << "Max Value : " << list.max();
return 0;
}
Learn more about elements
https://brainly.com/question/28565733
#SPJ4