| | |
Pointers and Dynamic Arrays
![]() |
•
•
Join Date: Aug 2005
Posts: 20
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jun 2005
Posts: 28
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Aug 2005
Posts: 20
Reputation:
Solved Threads: 0
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???
{
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???
C Syntax (Toggle Plain Text)
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???[/QUOTE]
![]() |
Similar Threads
- Differences Between Java and C/C++ (C++)
- Why use dynamic cast (C++)
- Purpose of Pointers? (C++)
- How to pass dynamic arrays? (C)
- Creating dynamic array structures (C++)
- Creating dynamic arrays (C++)
- Huge Dynamic arrays in QB45, BC7 (Legacy and Other Languages)
- Dynamic arrays inside a class? (C++)
- Help w/ dynamic list funtction definitions (C++)
Other Threads in the C Forum
- Previous Thread: Find any root of a number
- Next Thread: how to set file access time
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer linked linkedlist linux linuxsegmentationfault list lists locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open opensource owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






