Pleae help me with this C++ question, ill upvote thanks.
Write the definitions of the functions of the class orderedArrayListType that are not given in this
chapter.
please write a main.cpp and orderedArrayListTypeImp.cpp file and all the file that is given is
everything i have for this task
main.cpp
#include
#include "unorderedArrayListType.h"
using namespace std;
int main() {
// Write your main here
return 0;
}
////////////
orderedArrayListType.h
#ifndef H_orderedArrayListType
#define H_orderedArrayListType
#include "arrayListType.h"
class orderedArrayListType: 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 insert(int insertItem);
void remove(int removeItem);
orderedArrayListType(int size = 100);
//Constructor
};
#endif
/////////////////
orderedArrayListTypeImp.cpp
/////////////////////////////
arrayListType.h
#include
#include "orderedArrayListType.h"
using namespace std;
void orderedArrayListType::insert(int insertItem)
{
if (length == 0) //list is empty
list[length++] = insertItem; //insert insertItem
//and increment length
else if (length == maxSize)
cout << "Cannot insert in a full list." << endl;
else
{
//Find the location in the list where to insert
//insertItem.
int loc;
bool found = false;
for (loc = 0; loc < length; loc++)
{
if (list[loc] >= insertItem)
{
found = true;
break;
}
}
for (int i = length; i > loc; i--)
list[i] = list[i - 1]; //move the elements down
list[loc] = insertItem; //insert insertItem
length++; //increment the length
}
} //end insert
int orderedArrayListType::seqSearch(int searchItem) const
{
int loc;
bool found = false;
for (loc = 0; loc < length; loc++)
{
if (list[loc] >= searchItem)
{
found = true;
break;
}
}
if (found)
{
if (list[loc] == searchItem)
return loc;
else
return -1;
}
else
return -1;
} //end seqSearch
void orderedArrayListType::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
{
cout << "This is a sorted list. Inserting at the proper place."
<< endl;
insert(insertItem);
}
} //end insertAt
void orderedArrayListType::insertEnd(int insertItem)
{
if (length == maxSize) //the list is full
cout << "Cannot insert in a full list." << endl;
else
{
cout << "This is a sorted list. Inserting at the proper "
<< "place." << endl;
insert(insertItem);
}
} //end insertEnd
void orderedArrayListType::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
{
removeAt(location);
insert(repItem);
}
} //end replaceAt
void orderedArrayListType::remove(int removeItem)
{
int loc;
if (length == 0)
cout << "Cannot delete from an empty list." << endl;
else
{
loc = s.
Pleae help me with this C++ question, ill upvote thanks.Write the .pdf
1. Pleae help me with this C++ question, ill upvote thanks.
Write the definitions of the functions of the class orderedArrayListType that are not given in this
chapter.
please write a main.cpp and orderedArrayListTypeImp.cpp file and all the file that is given is
everything i have for this task
main.cpp
#include
#include "unorderedArrayListType.h"
using namespace std;
int main() {
// Write your main here
return 0;
}
////////////
orderedArrayListType.h
#ifndef H_orderedArrayListType
#define H_orderedArrayListType
#include "arrayListType.h"
class orderedArrayListType: 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 insert(int insertItem);
void remove(int removeItem);
orderedArrayListType(int size = 100);
//Constructor
};
#endif
/////////////////
orderedArrayListTypeImp.cpp
/////////////////////////////
2. arrayListType.h
#include
#include "orderedArrayListType.h"
using namespace std;
void orderedArrayListType::insert(int insertItem)
{
if (length == 0) //list is empty
list[length++] = insertItem; //insert insertItem
//and increment length
else if (length == maxSize)
cout << "Cannot insert in a full list." << endl;
else
{
//Find the location in the list where to insert
//insertItem.
int loc;
bool found = false;
for (loc = 0; loc < length; loc++)
{
if (list[loc] >= insertItem)
{
found = true;
break;
}
}
for (int i = length; i > loc; i--)
list[i] = list[i - 1]; //move the elements down
list[loc] = insertItem; //insert insertItem
length++; //increment the length
}
} //end insert
int orderedArrayListType::seqSearch(int searchItem) const
{
int loc;
bool found = false;
3. for (loc = 0; loc < length; loc++)
{
if (list[loc] >= searchItem)
{
found = true;
break;
}
}
if (found)
{
if (list[loc] == searchItem)
return loc;
else
return -1;
}
else
return -1;
} //end seqSearch
void orderedArrayListType::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
{
cout << "This is a sorted list. Inserting at the proper place."
<< endl;
insert(insertItem);
}
} //end insertAt
void orderedArrayListType::insertEnd(int insertItem)
{
if (length == maxSize) //the list is full
4. cout << "Cannot insert in a full list." << endl;
else
{
cout << "This is a sorted list. Inserting at the proper "
<< "place." << endl;
insert(insertItem);
}
} //end insertEnd
void orderedArrayListType::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
{
removeAt(location);
insert(repItem);
}
} //end replaceAt
void orderedArrayListType::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
orderedArrayListType::orderedArrayListType(int size)
: arrayListType(size)
{
5. }
/////////////////
arrayListTypeImp.cpp
#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;
6. }
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;
}
7. 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