Archived

This topic is now archived and is closed to further replies.

Having Some Problems Yet Again...(dynamically allocated arrays)

This topic is 5535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m currently working on grading program that displays; -the number of scores a student has -the avg score -the median -top ten scores -worse ten scores -standard deviation At first this program used vectors and such, but now I need to change it to use dynamically allocated arrays, which seems like I''ll have to basically recode everything (which is not good seeing that I had many troubles the first time around). The last program I got as far as calculating the avg and median, and part of the top ten, but now the guidelines for this program has changed and instead of using std::vector I need to use dynamically allocated arrays. Anyone here willing to lend me some help, because now I have no idea on where to begin. I don''t want the *exact* coding for any of the problems, I just need help in getting started like how should I go about creating the functions (I have a feeling I''ll need to use pointer within the function parameters). I''m still not sure about standard deviation (I''m getting there though) and I''ve had some problems with the sorting and displaying of the top ten/worse scores. So...can someone point me in the right direction, I''d really appreciate it.

Share this post


Link to post
Share on other sites
Could I do something like this to fill the dynamic array:



typedef int* IntPtr;

int main()
{

IntPtr Grades;
int Max_Size = 100;

Grades = new int[Max_Size];

cout << "Enter Grades: ";

for (int index = 0; index != Max_Size; index ++)
{
cin >> Grades[index];

}




return 0;

}


[edited by - -dcx- on October 20, 2002 2:22:00 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why don''t you ask your teacher/prof. This sounds like a homework question.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well if its not your homework...

The main thing with dynamic memory is that you don''t know what size you''ll need until its running. In your example code you have a MAX_SIZE which you use to allocate memory for an array of that size and then you take input to fill it up. By hardcoding that as 100 you are avoiding it being dynamic, ie. you are allocating them memory with "new" but the size is already determined. I would think that the first input you take in would be the size and then you''d use that number to allocate space. This way it would truly be "dynamic".

Share this post


Link to post
Share on other sites