The skeleton of the program in from the bo0k by DS Malik.
Three functions were not defined there and I defined there and I defined them myself viz:
int search(int searchItem);
void remove(int removeItem);
void destroy();
#include<iostream>
usingnamespace std;
class intListType
{
public:
bool isEmpty();
//Function to determine whether the list is empty.
//PRecondidition: The list must exist.
//Postcondition: REturns true if the list is empty,
// false otherwise
bool isFull();
//Function to determine whether the list is full.
//Precondiion: The list must exist
//Postcondition: Returns true if the list is full,
// false otherwise
int search(int searchItem);
// Function to determine whether searchItem is in the list,
// Postcondition: If searchItem is in the list,
// returns its index, that is,
// its position in the list;
// otherwise , it returns -1.
void insert(int newItem);
//Function to insert newItem in the list.
//Precondiion: The list must exist and must not be full
//Postcondition: newItem is inserted in the list and
// the length is incremented by one.
void remove(int removeItem);
//Function to delete removeItem from the list.
//Precondiotn: The list must exist and must not be empty
//Postcondition: If found, removeItem is deleted
// from the list and the length is
// decremented by one. otherwise,
// an appropriate message is printed.
void destroy();
//Function to remove all the elements of the list.
// Precondition: The list must exist.
//Postcodition: The length is set to 0
void printList();
// Function to output the elements of the list.
//Precondition: The list must exist
//Postcondition: The elements of the list are
// printed on the standard output device
intListType();
//default constructor
//Postcondition: length = 0
private:
int list[1000];
int length;
};
bool intListType::isEmpty()
{
return (length == 0);
}
bool intListType::isFull()
{
return (length == 1000);
}
int intListType::search(int searchItem)
{
int location = 0;
bool found = false;
int number_used;
while((!found) && location < number_used)
if(searchItem == location)
found = true;
else
location++;
if(found)
return location;
elsereturn -1;
}
void intListType::insert(int newItem)
{
list[length] = newItem;
length++;
}
void intListType::remove(int removeItem)
{
list[length] = removeItem;
length--;
}
void intListType::destroy()
{
//delete [] list;
length = 0;
}
void intListType::printList()
{
//int newItem;
//cout << list[newItem];
for(int i = 0; i < length; i++) {
cout << list[i] << endl;
}
}
intListType::intListType()
{
length == 0;
}
int main()
{
int newItem ;
intListType list1;
list1.insert(54);
list1.insert(544);
list1.printList();
return 0;
}
The program bombs out when I run it
Help me as to why it does not run