I am currently tasked with creating a function that takes information from a file and stores it into a set of arrays. The first array is a one-dimensional array, storing names of students, while the second array is a two-dimensional array that stores the values of several tests. A sample of the input text from the file is below:
Jon 81 83 77 90
Amanda 80 91 95 93
Sarah 78 81 11 90
Aaron 92 83 44 69
Blair 23 45 96 38
Clark 60 85 45 39
Kenney 77 31 52 74
John 93 94 89 77
Sammy 79 85 28 93
Glenn 85 72 49 75
Brad 74 65 49 96
The first array is called studentNames[] and only stores the names. The second array is studentGrades[][] and stores the grades from four tests. I have run myself in about a million circles on this project so far. I thought I had a good way to get the information from the file, but I cannot figure out how to get the values out of each line.
int main()
{
ifstream fileIn ("grades.txt");
string line;
for (int i = 0; i < 11; i++)
{
getline(fileIn, line);
int lineLen = line.length();
cout << line << " Length = " << lineLen << endl;
}
return 0;
}
That will display the lines, but I cannot figure out how to get the actual value of the pieces stored into an array. I know this question is probably poorly worded, but I am trying to figure out how to word it properly. I will update with more information if I can.
The above code gives me this output:
Jon 81 83 77 90 Length = 15
Amanda 80 91 95 93 Length = 18
Sarah 78 81 11 90 Length = 17
Aaron 92 83 44 69 Length = 17
Blair 23 45 96 38 Length = 17
Clark 60 85 45 39 Length = 17
Kenney 77 31 52 74 Length = 18
John 93 94 89 77 Length = 16
Sammy 79 85 28 93 Length = 17
Glenn 85 72 49 75 Length = 17
Brad 74 65 49 96 Length = 16
If I add the line to the main body:
string names[11];
Then add this to the loop:
fileIn >> names[i];
cout << names[i];
I end up with no change at all in the output. However, if I comment out the other cout statement that shows the lines, I get the following output:
Amanda Sarah Aaron Blair Clark Kenney John Sammy Glenn Brad
First off, the iterator "i" should be starting at 0, but it is ignoring the first name in the list. Now, if I keep the original comment and just add the names[i] to the output:
cout << line << " Length = " << lineLen << names[i] << endl;
I end up with:
Jon 81 83 77 90 Length = 15Amanda
80 91 95 93 Length = 12Sarah
78 81 11 90 Length = 12Aaron
92 83 44 69 Length = 12Blair
23 45 96 38 Length = 12Clark
60 85 45 39 Length = 12Kenney
77 31 52 74 Length = 12John
93 94 89 77 Length = 12Sammy
79 85 28 93 Length = 12Glenn
85 72 49 75 Length = 12Brad
74 65 49 96 Length = 12
As the output. So it is removing the names from the front of the line and sticking them in the back of the line above. In all cases, the first name on the list is ignored.
EDIT: To clarify, I have been working on the problem for three days, I am currently trying to recreate the steps I have taken over the past few days so I can show what I have done and what behavior I have encountered. It is a time-consuming process trying to recreate these steps.