This is a beginner C++ homework problem, I know about vector, but it is not allowed to use in this assigment. I searched around and I found how to make an
array of unknown size too. But it is slightly trickly (sort of). The example I read are all along the lines of: get an input, then create the array base on that input (size n).
I have created this student class, but now I need an
array to store them. I do not know in advance how many students there are going to be. I only have an input of text file with each student on one line. The format is below, the sample is about 5, but I don't know how many the teacher will use to test my program.
Input file like this:
George Chan Computer_Science New York 23
Johnny Chan Computer_Science New Jersery 22
But the problem is I don't know how many students are there until I finish reading the whole text tile (or I don't know if there are other way to do it). My current approach is to read it line by line, increment a counter
studentCounter, until I finish, then I create my
Student* myRoster = Student[studentCounter]. But then when I have to start reading the file again. And go line by line to parse the information and create a
Student object and let a
myRoster[x] points to it. I feel like I am sort of doing the work twice just to have the right size. Are there some tricks or things I am missing?