I wrote a program to do the following:
Write a destructor to return the dynamic memory used by the list to the heap.
Write a function which returns the number of items in the list.
Write a function which returns true if the list is full.
Write a function to add one item to the list. The argument of the function contains the item to be added.
Write a function to remove all of the items from the list.
Write a function to print the contents of the list to a report.
write a function to display the contents of the list to the display.
i woul like to write a small program in main to test the array list.
using namespace std;
int main()
{
List a(1);
a.add(1);
return 0;
}
#include <iostream>
#include<fstream>
#include<string>
#include<iomanip>
List::List(int max)
{
int current_length=0;
typedef int*item;
item a;
a = new int[max];
if ( a==NULL)
{
cout<< "Error : Insufficient memory.\n";
exit(1);
}
Max_number=max;
}
int List::length ()
{
return(current_length);
}
void List::add (int new_item)
{
cout<<"Enter a new item to the list: "<<endl;
cin>>current_length;
if(a.full())
{
cout<<"Error:adding to a full list."<<endl;
exit(1);
}
else
{
a[current_length]=new_item;
current_length=current_length+1;
}
}
int List::full()
{
return(current_length==Max_number);
}
void List::erase ()
{
current_length=0;
}
List::~List()
{
delete[] a;
}
i want to add items to the list and test it in main but still I have error message which i do not know why please i need help?