I am having problems with the most important section of this program. I must admit after reading, I understand the concept, but applying it to this particular program is not coming through. I am attaching the source code but the portion I am having problems with is the following:

void add_item(double number)

What I am trying to do is also attached in the sample snapshot. I know what I need to do but have a hard time implementing. I know I should add entries until it reaches the max. Once it is at the max, add the next one but double the maximum. I hope someone can help.

Recommended Answers

All 4 Replies

In your solution void add_item(double number) should be a member of the class.

It should be defined using

void List::add_item(double number) outside the class

Also I noticed that you never use the number parameter within the add_item method.

Does your progam compile?

-------------------------
Programming ( Assignment / Project ) Help

in the default constructure allocate the array with max number of doubles.

function add_item is all f**ked up. change the name to list::add_item and delete all its contents.

if size == MAX_LIST_SIZE then reallocate the array, otherwise just insert the new number into list[size++];

void list::add_item(double number)
{
    ArrayPtr *m = new ArrayPtr double [d1];
    delete [m];
    int i, d1, d2;

    if size = MAX_LIST_SIZE
    {
        for (i = 0; i < d1; i++)
            m[i] = new int[d2]

    }
    else
    {
        list [size] = number;
        size++;
    }
}

I'm not getting it. Once I check the size, add it and then count.....else just add the record???

void list::add_item(double number)
{
    if (size == max )
    {
               // reallocate the array 
               ArrayPtr m = new ArrayPtr [max + MAX_LIST_SIZE];
              // copy existing data into new array
               memcpy(m, list, size * sizeof(double));
              // delete old array object
              delete[] list;
              // reset list
              list = m;
              // bump array size
              max += MAX_LIST_SIZE;
        }
       // add number to the list
    list [size] = number;
    size++;
}

I'm not getting it. Once I check the size, add it and then count.....else just add the record???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.