Question
Hello i could use some help creating this code in c++ thanks. primary tasks for this exercise are to complete the header file by writing
Hello i could use some help creating this code in c++ thanks.
primary tasks for this exercise are to complete the header file by writing the definition of four functions with its description below:
removeAt function to remove the item from the list at the position specified by location. Because the list elements are in no particular order (unsorted list), you could simply remove the element by swapping the last element of the list with the item to be removed and reducing the length of the list.
insertAt function - to insert an item in the list at the position specified by location. The item to be inserted is passed as a parameter to the function.
print function to output the elements of the list.
min function to output the smallest element of the list
- And demonstrate the class arrayListType by write the main program (cpp) that asks a user to enter 5 integers. After displaying the entered 5 integers, ask the user the position of the item to be deleted and inserted. Your program should include error checking if the position is out of range or array is full, display the final list of array and find the minimum value.
// file name: arrayListType.h
// Spring 2020
#ifndef H_arrayListType
#define H_arrayListType
#include
#include
using namespace std;
template
class arrayListType
{
public:
void print() const;
//Function to output the elements of the list
//Postcondition: Elements of the list are output on the
// standard output device.
void insertAt(int location, const elemType& insertItem);
//Function to insert an item in the list at the
//position specified by location. The item to be inserted
//is passed as a parameter to the function.
//Postcondition: Starting at location, the elements of the
// list are shifted down, list[location] = insertItem;,
// and length++;. If the list is full or location is
// out of range, an appropriate message is displayed.
void removeAt(int location);
//Function to remove the item from the list at the
//position specified by location
//Postcondition: The list element at list[location] is removed
// and length is decremented by 1. If location is out of
// range,an appropriate message is displayed.
elemType min() const;
//find the minimum value of the array
arrayListType(int size = 5);
//constructor
//Creates an array of the size specified by the
//parameter size. The default array size is 5.
//Postcondition: The list points to the array, length = 0,
// and maxSize = size
~arrayListType();
//destructor
protected:
elemType *list; //array to hold the list elements
int length; //to store the length of the list
int maxSize; //to store the maximum size of the list
};
/* +++++ Write function definition for the four functions below ++++ */
// print function definition
template
void arrayListType
{
// your code here
// your code here
} // end print function
// find minimum value of the list
template
elemType arrayListType
{
// your code here
// your code here
} // end min function
// insertAt function definition
template
void arrayListType
(int location, const elemType& insertItem)
{
// your code here
// your code here
} //end insertAt function
// removeAt function definition
template
void arrayListType
{
// your code here
// your code here
} //end removeAt function
// ++++ You need the two templates below to avoid errors +++++++
// constructor function
template
arrayListType
{
if (size < 0)
{
cerr << "The array size must be positive. Creating "
<< "an array of size 5. " << endl;
maxSize = 5;
}
else
maxSize = size;
length = 0;
list = new elemType[maxSize];
assert(list != NULL);
}
// destructor function
template
arrayListType
{
delete[] list;
}
#endif
Step 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