Functions and Arrays... Help!!!

I need to write a program for class that calculates student averages and quiz averagages. It has to read a 2-dim array from a file that looks like this:
10 10 10
2 0 1
8 6 9
8 4 10
The four students are the rows and the three quizzes are the columns.
Then I have to change the 2-dim inout into 1-dim arrays to get this output.
My output needs to look like this:
Student Averages Quizzes
1 10.0 10 10 10
2 1.0 2 0 1
3 7.7 8 6 9
4 7.3 8 4 10
Quiz Averages = 7.0 5.0 7.5

So, this is what I have so far. I used the prototypes my insturctor gave us, but I don't know if I am calling them correctly in the main. Then after the main. I am processing the gerMatrix, compStuAvg, and compQuizAvg and I need to display my results using my displayData, but here I get epically lost. Can I get a push in the right direction? Do I need a loop in the main also to process my data? I feel quite lost. Thanks to anyone who takes a look. And don't be mean! I'm a beginner!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* Program: Grade Matrix
 * Description: To manipulate one and two dimensional arrays and pass arrays as
 * arguments to functions in order to calcualte student averages and quiz 
 * averages.
 */
 
 # include <fstream>
 # include <iostream>
 
 using namespace std;
 
 const int NUM_STU = 4;
 const int NUM_QUIZ = 3;
  
 // function prototypes
 void getMatrix (ifstream&, int matrix [] [NUM_QUIZ]);
 //reads matrix from file
 void compStuAvg (const int matrix [] [NUM_QUIZ], float []); 
 //calcs avgs to a one-dimensional array
 void compQuizAvg (const int matrix [] [NUM_QUIZ], float []); 
 //calcs quiz avgs
 void displayData (ofstream& outfile, const int matrix [] [NUM_QUIZ], const float [], 
 const float []);
 //displays data
 
 int main ()
 {
     ifstream data;
     ofstream out;
     int matrix [NUM_STU][NUM_QUIZ]; 
     float student_avg, quiz_avg;
     
             
     
     data.open ("grade_matrix.txt"); //file for input
     if (!data)
        {
               cout << "Error!!! Failure to open grade_matrix.txt" << endl;
               system ("pause");
               return 1;
        }
     out.open ("out.txt"); //file for output
     if (!out)
        {
               cout << "Error!!! Failure to open out.txt" << endl;
               system ("pause");
               return 1;
        }
        
               
        getMatrix (data, matrix);
        compStuAvg (matrix, student_avg);
        compQuizAvg (matrix, quiz_avg);
        displayData (outfile, matrix, student_avg, quiz_avg); 
        
        //do I need a loop here??? Such as a while (data)... {}
        
        
        
     system ("pause");
     return 0;
     
 } //end of main
 
 void getMatrix (ifstream& data, int matrix [] [NUM_QUIZ])
 {
           
      for (int i = 0; i < NUM_STU; i++)
      {
                  
          for (int j = 0; j < NUM_QUIZ; j++)
          {
            data >> matrix [i][j];
          }//inner loop
      }//outer loop
      
 }//getMatrix
 
 void compStuAvg (const int matrix [] [NUM_QUIZ], float student_avg [])
 {
      float sum; 
      for (int i = 0; i < NUM_STU; i++)
      {
          sum = 0;
          for (int j = 0; j < NUM_QUIZ; j++)
              sum = sum + matrix [i][j]; 
          student_avg [i] = sum / NUM_STU;    
          //should I be returning a value or even just 0???
           
          
      }
 }
 //compStuAvg
 
 void compQuizAvg (const int matrix [] [NUM_QUIZ], float quiz_avg []);
 {
      float sum;
      for (int i = 0; i < NUM_STU; i++)
      {
          sum = 0; 
          for (int j = 0; j < NUM_QUIZ; j++)
              sum = sum + matrix [i][j];
          quiz_avg [i] = sum / NUM_QUIZ;
            //should I be returning a value or even just 0???
          
      }
 }
 //compQuizAvg
 
 void displayData (ofstream& outfile, const int matrix[] [NUM_QUIZ], 
 const float student_avg[], const float quiz_avg[]) 
 outfile << /*??? I'm lost here after I do the above calculations, how do I 
 display that??? I can't find a good example anywhere quite like this in my book
 or on the web...
 
 
 

 
 
 
        
              
 




































/
  
 
      
       */
//do I need a loop here??? Such as a while (data)... {}
No, unless you want to repeat your i/o.

//should I be returning a value or even just 0???

No. Void functions would cause syntax errors if you try to return something from them. You can use the return statement (simply return;), if you want to end the function execution, but that is not neccesary.

About displaying the data, you can simply loop through the arrays and cout<< the values.
Like:
1
2
3
4
5
6
for(int i=0;i<NUM_STU;i++){
cout <<student_avg[i];
for(int j=0;j<NUM_QUIZ;j++)cout<<matrix[i][j]<<"\t";
cout<<"\n";
};
for(int i=0;i<NUM_QUIZ;i++)cout<<quiz_avg[i]<<"\t";

(note that it might not be exactely accurate, but that's the idea).

I hope this helps a bit.
dahm! you gave a wide space at the end.
People generally won't help you debug unless you give us some idea of where to look for the problem or what the problem is.
@Ramses12
Thanks so much!!!! You are awesome. I really appreciate you taking a look at my mess. Haha. I'll clean this up and hopefully it all goes well from here! :)
Topic archived. No new replies allowed.