|
-
May 3rd, 2011, 05:58 PM
#1
C++ question about arrays....
Hello.
I'm working on a program that is about to get student's information.
so when a student uses the program, a field of memory should be allocated to him/her to save his/her information.
unfortunaly i dont know how many students there are, so i cant use arrays because of constant size..therefor linked lists are being used...
But i was wondering if this idea would work too or not:
Code:
const int OldSIZE=5;
int *p=new int[OldSIZE];
so we have an array with size of 5 that can hold 5 student's records and can be accessed by pointer "p".
here is my idea and my problem that if we have a new student to save his/her data, how can i make a new array with new size that the new size is 1+OldSIZE and copy all information plus new students information to the new array?
Code:
size=size+1;
//size is 6 now. but we cant do it because it is constant
int *q=new int[size];
a code that can copy (array of pointer p) to (array of pointer q);
delete []p;
add the new student's info to the new array..
how can i make this idea work??
i hope i could explain it clearly, but ask me if ur confused what i meant...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|