data of file into array/ and calculate data

hello everyone, I'm a bit stuck right now.
i don't know exactly how to start , store and calculate the data from a file. this is what i have right now:


int main()
{
string data ;
ifstream myfile ("student_data.txt");
int students[16] = {} ;
const int array_size = 16;
int student[array_size];
int i = 0 ;

if(myfile.is_open())
{
while(getline(myfile,data))
{
istringstream iss(data);
int foo;
while(iss >> foo)
{
student[i]=foo;
cout << student[i] <<" ";
i++;
}

cout << i << endl;
i = 0;

{
cout << foo;
}

}



myfile.close();
}

thats is how it supposed to look :
Stdnt Id Ex ------- Assignments --------- Tot Mi Fin CL Pts Pct Gr
-------- -- ----------------------------- --- -- --- -- --- --- --
75359264 14 20 11 13 9 20 13 20 11 13 9 130 78 81 8 311 78 C+
90774483 39 19 20 20 9 17 19 15 18 13 10 151 55 72 8 325 81 B-
91817488 40 16 14 18 20 18 9 5 15 19 16 145 58 81 9 333 83 B
96666943 33 9 19 15 18 12 18 9 7 19 19 138 57 70 0 298 75 C
22397483 31 18 11 15 19 13 20 9 17 20 15 148 59 64 8 310 78 C+
51659342 22 19 12 15 17 15 20 14 14 20 16 150 79 89 3 343 86 B
01234567 22 18 11 17 20 18 18 5 18 20 18 158 60 56 8 304 76 C
96498948 22 10 12 12 18 20 13 17 9 18 9 129 63 67 8 289 72 C
...


can someone give me some pointers/explanations how to start?
thanks!
Okay, you look like you're getting the student id out of each record read (data).
Now, you need to read the assignments for each student.
You can do this one of two ways.
1) You can create a two dimensional array.
 
  int assignments[array_size][11];


2) The better approach would be to create a struct that represents a student (if you've covered structs):
1
2
3
4
5
6
7
8
9
10
  struct student 
  {  int student_id;
      int assignments[11];
      int midterm;
      int final;
      int pct;
     string grade;
  };

  student[array_size] students;


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.



thanks for replying , what would you recommend if i need to do so in 1D arrays?
thanks!
If you process one record at a time from the file, you only need an array for assignments.
Topic archived. No new replies allowed.