Hello Joseph..
can you help me answer with this please..

array of student score declared as dynamic data
-declared a dynamic data array to contain the scores for 10 students.then step through the array assigning the counter as the value of the score for that array element.finally,write another for loop that displays each score.remember that you have to use pointer to access the array.you can do this in three steps:
1.)declare a pointer and allocate space for your array
int *arr,new int[size];
2.)use a for loop to step through the array (using either pointer or the subscript notation)
for(int i=0;i<size;i++)
3.)finally,use another for to display the score
for(int i=0;i<size;i++)
cout<<"score for student"<<i+1":"

NOTE: dont forget to use delete to free up space used by the array

hope you can help me with this its very important!!
thank in advance Joseph..

Hi, Sean.

Honestly, I'm not even sure you need any help on this one.  The code you have provided does everything except delete the dynamic memory (with a tiny bit of modification, that is).  Putting together all the code you provided in your question, and adjusting a couple of lines to account for what would otherwise be compile errors (and some reformatting to make it more like I would write it), the code looks like:

   int *arr = new int[size];

   for (int i = 0; i < size; i++)

   for (int i = 0; i < size; i++)
       cout << "score for student " << i + 1 << " : " << *(arr+i) << endl;

You see that I changed the code for part 1 to actually use the assignment operator, making it a compilable line of code.  I also changed the cout statement to be on one line (personal preference) and fixed an error by adding in a new << operator after the i + 1 part.

The only thing lacking from this code to make it a functional program and to meet the given requirements is the declaration of the main function, a define (or variable) for the array size, and the deletion of the dynamically allocated array.  The only real "gotcha" in all of that is the deletion of the dynamic memory.  Because you have dynamically allocated an array, you must make sure to use the array form of deletion:

   delete [] arr;

Because I prefer people to try things for themselves first, I'll leave the rest to you to attempt.  Go ahead and put together the full program, then send the completed code back to me as a followup and I'll look it over.

If you have any questions, feel free to ask.  I'm here to help. :)


All Answers

Answers by Expert:

Ask Experts


Joseph Moore


I've been programming in one form or another since my brother taught me BASIC when I was 6. I've been programing professionally since I was 20, first web development with HTML, JS, DHTML, CSS, etc., then I became a video game developer, writing code in C, C++, C#, SQL, assembly, and various scripting languages. I've even written my own scripting languages, custom designed for the games I was making. I also dabble in Java, PHP, and Perl. I've worked on pretty much every aspect of game development, including graphics, audio, gameplay, tool, UI, input, animation, and physics.


I've been writing C++ code for 12 years, both on my own in my spare time and professionally.


Bachelor of Science in Game Design and Development, Full Sail University, Winter Park, FL

Awards and Honors
Salutatorian and Advanced Achiever Awards at Full Sail; Independent Games Festival Student Showcase winner, 2004; Featured article on Gamasutra about an experimental game developed in 2004

©2017 About.com. All rights reserved.