Hi guys,

I have been given a task in my C++ course to develop an application that will ask the names of the students and store the entered values into a string type array. Considering each student has participated in four exams, the program should ask the points received and store them into an int type array. Then the application should display the names of the students and the average value of the exams from each.

Key Points:

a) Use always pointer notations when writing/reading information to/from arrays.
b) You can’t ask “How many names will be inputted”.

I know how to develop the program without using pointers, but that is the whole point of the exercise. I guess pointers are the most challenging part of C++, any help would be much appreciated.

Thank you in advance.

Kind Regards,


5 Years
Discussion Span
Last Post by croussou

I guess pointers are the most challenging part of C++, any help would be much appreciated.

Pointers are fantastically simple and easy; they're just often badly taught using clumsy metaphors that do more harm than good.

Anyway, here's some code that takes in as many names as you care to enter, managing the array size as it goes. Read, digest, understand. Then you can write your own, and develop the code to hold each student's score as well. Any questions, ask them here, and we'll answer.

#include <iostream>
#include <string>

using namespace std;

// start by allocating space for ten strings

int maxNumAllowed = 10;
int numStudents = 0;
string* pStudentArray = new std::string[10];

int main()

char moreStudents = 'Y';
while(moreStudents == 'Y')
    if (numStudents == maxNumAllowed)
	// need bigger array
	maxNumAllowed += 10;
        cout << "Making new array of size" << maxNumAllowed << endl;
        string* newPStudentArray =  new std::string[maxNumAllowed];
        for (int i =0; i < numStudents; ++i)
	    newPStudentArray[i] = pStudentArray[i];
	// have now copied all old data to new array
	delete[] pStudentArray; // Tidy away old array
	pStudentArray = newPStudentArray; // now pStudentArray points to more space
    cout << "Next student name?" << endl;
    cin >> pStudentArray[numStudents];
    cout << "Another? (Y/N)" << endl;
    cin >> moreStudents;

cout << "You entered " << numStudents << "students. They are: ";
for (int i =0; i < numStudents; ++i)
  { cout << pStudentArray[i] << " ";}

return 0;

Edited by Moschops: n/a



Thank you for your prompt reply.

I will have a look at the code you provided and then try develop my own.

I will let you know in case something else comes up.

Once again, thank you.

Kind Regards,


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.