Please make a class file in C++. The test cpp is attached at the bottom. Array L
ID: 3663038 • Letter: P
Question
Please make a class file in C++. The test cpp is attached at the bottom.
Array List a A pointer that holds the memory address for the dynamically allocated array. nt capacity stores the number of elements of the array. capacity int length stores the number of values currently in the list. Unless the array is full, length: int the length will be less than capacity +AmayList( c int) constructor dynamically allocates an array c elements long. Stores the memory AmayList0 address in a. Sets capacity to c. Sets length to 0. +clear0 void destructor deletes the array. +insert i: int):int append( i int): int glearo empties the list. (IOW, sets length to 0 in ArrayList) +remove(i int): int +peek( i: int& int const inserto-inserts the value in parameter i into the list, IN ASCENDING SFull(): bool const ORDER. Returns 0 if successful, -1 otherwise. +isEmpty(): bool const appendo adds the value in parameter ito the end of the list. Returns 0 if +getLength(): int const successful, -1 otherwise. +find(i int) nt const remgyen removes the first value found in the list matching the value in +print) :void const parameter i. Returns 0 if successful, -1 otherwise. isEullo returns true if the list is full, false otherwise. isEmpty returns true if the list is empty, false otherwise. findo returns the element index of a value matching the value in parameter i f found in the list, -1 otherwise printQ displays the values in the list on a single line, separated by spaces. peeko assigns the value at the front of the list to reference parameter i Returns 0 if successful -1 otherwise. Does not alter the list in any way. otes: insert and append() would normally not be within the same class, as they have incompatible logic. You are including them both here to avoid writing a second class whose code differs only by one method. When I test your class, insert and append will NOT be invoked on the same object without calling clear first. This way, the object will be tested as an ordered List or an Unordered list. When could a method fail? For example, insert could fail if the array is full.Explanation / Answer
class ClassArrayList {
// data members
static boolean success;
int *q;
int capacity;
static int ListLength=100;
int length;
// linked list
struct tag {
int data;
struct tag *next;
} *List[ListLength];
// function members
// constructor
ClassArrayList();
~ClassArrayList(); // destructor
void clear() {
// this will empty the list
int i;
int ListLength = 100;
int List[ListLength];
for(i=0; i<ListLength; i++)
List[i]=0;
} // end function clear
int insert(int data) {
List[i] = data;
// now sort the list into Ascending order:
int j, temp;
for(int i=0; i<=ListLength-1;i++)
for(j=i+1; j<ListLength; j++)
// compare and swap if needed
// a simple bubble sort
if (List[i] > List[j]) { // then swap
temp = List[i];
List[i] = List[j];
List[j] = temp;
} // end if
// end for inner j
// end for outer i no need for }
if (success)
return 0;
else
return -1;
} // end function insert
int append(int newData) {
if (List[ListLength] = newData) success = true;
else success = false;
if (success)
return 0;
else
return -1;
} // end function append
int remove(int getRidOfMe) {
int i;
for(i=0; i<=ListLength; i++)
if (List[i]->data == getRidOfMe)
List->next = List->next->next;
if (success)
return 0;
else
return -1;
} // end remove
boolean isFull() {
if ( List[ListLength] != 0 ) return true;
else return false;
}
boolean isEmpty() {
if (List[0] == 0 ) return true;
else return false;
}
int find(int whereAmI) {
for(int i=0; i<ListLength; i++)
if ( List[i]->data == whereAmI ) return i;
} // end function find where Am I
void print() {
cout << endl;
for(int i=0; i<ListLength; i++)
cout << List[i]->data << " ";
}
int peek() {
}
} // end class ClassArrayList