Computers and Technology

The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that it is written as a value returning function, returning the required item. If the location of the item to be returned is out of range, use the assert function to terminate the program. Also, write a program to test your function. Use the class unorderedArrayListType to test your function. we have arrayListType. h
#ifndef H_arrayListType
#define H_arrayListType
#include
#include
class arrayListType {
public:
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;
virtual void insertEnd(int insertItem) = 0;
void removeAt(int location);
// void retrieveAt(int location, int& retItem) const;
int retrieveAt(int location, array){
if(location <= array. size() - 1){
return array[location]; } else{
cout<<"Location out of range";
assert(); // Assuming the assert function is defined in the program. }}
int arrayListType::retrieveAt(int location) const{
int retItem = 0;
assert( (location < 0) || (location >= length));
retItem = list[location];
return retItem;} //end retrieveAt*/
//int retrieveAt(int location) const;
virtual void replaceAt(int location, int repItem) = 0;
void clearList();
virtual int seqSearch(int searchItem) const = 0;
virtual void remove(int removeItem) = 0;
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
arrayListTypeImp. cpp

#include
#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 < length; i++)
cout << list[i] << " ";
cout << endl;
} //end print
bool arrayListType::isItemAtEqual(int location, int item) const{
if (location < 0 || location >= length) {
cout << "The location of the item to be removed "
<< "is out of range." << endl;
return false;
}
else
return (list[location] == item);
} //end isItemAtEqual
void arrayListType::removeAt(int location){
if (location < 0 || location >= length)
cout << "The location of the item to be removed "
<< "is out of range." << endl;
else {
for (int i = location; i < length - 1; i++)
list[i] = list[i+1];
length--;
}
} //end removeAt
void arrayListType::retrieveAt(int location, int& retItem) const{
if (location < 0 || location >= length)
cout << "The location of the item to be retrieved is "
<< "out of range" << endl;
else
retItem = list[location];
} //end retrieveAt
void arrayListType::clearList(){
length = 0;
} //end clearList
arrayListType::arrayListType(int size){
if (size <= 0; {
cout << "The array size must be positive. Creating "
<< "an array of the size 100." << endl;
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 < length; j++) //copy otherList
list [j] = otherList. list[j];
}//end copy constructor

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 14:30, carter1809
Choose the answers that best complete each sentence. on average, are more expensive than other kinds of postsecondary schools. the cost of room and board includes. to save money, some students attend auniversity in their home state.
Answers: 2
image
Computers and Technology, 23.06.2019 19:40, Latoyajenjins1789
Use a physical stopwatch to record the length of time it takes to run the program. calculate the difference obtained by calls to the method system. currenttimemillis() just before the start of the algorithm and just after the end of the algorithm. calculate the difference obtained by calls to the method system. currenttimemillis() at the start of the program and at the end of the program so that the elapsed time includes the display of the result. use the value returned by the method system. currenttimemillis() just after the end of the algorithm as the elapsed time.
Answers: 3
image
Computers and Technology, 24.06.2019 17:30, NEONREDBLADE
Match the following. 1. formatting that is applied when cell data meets certain criteria 2. borders with formats not found on the border tool 3. a shortcut bar that contains tools for commonly used formats 4. formats that can be applied to numbers conditional formatting custom borders format bar number formats
Answers: 3
image
Computers and Technology, 25.06.2019 21:00, jatavispillow
An in active student wants to become more physically active but does not want the money to pay for gym membership what is the most effective think she can do to develop realistic fitness routine
Answers: 2
Do you know the correct answer?
The function retrieveAt of the class arrayListType is written as a void function. Rewrite this funct...

Questions in other subjects:

Konu
Mathematics, 03.02.2021 23:10
Konu
English, 03.02.2021 23:10