My assignment is to create a 2D array to create a grade book so that each student's name can be displayed next to all of the assignments.
The text file I am reading into my program to create the grade book is as follows:
Student1 98 71 73 71 82 88 77
Student2 87 83 98 76 76 80 75
Student3 82 92 85 80 88 79 87
Student4 84 95 89 70 86 90 99
Student5 96 90 87 84 100 72 73
Student6 86 75 98 71 75 89 72
Student7 70 84 85 80 90 90 78
Student8 77 96 97 75 77 73 71
Student9 89 79 87 86 70 77 84
Student10 74 79 87 96 96 94 73
Student11 90 88 95 95 90 86 76
Student12 92 87 80 87 98 71 76
Student13 79 94 75 93 86 88 93
Student14 82 90 92 83 88 94 84
Student15 79 78 72 72 81 90 90
Student16 100 84 79 95 78 77 95
Student17 77 98 98 98 74 80 89
Student18 83 84 96 75 98 75 99
Student19 94 98 89 86 98 76 84
Student20 87 76 98 83 76 72 88
Student21 98 89 93 82 73 84 96
Student22 81 98 85 73 73 99 76
Student23 98 70 80 84 76 80 82
Student24 81 73 74 74 77 86 87
Student25 94 76 83 83 72 76 100
Student26 70 70 82 74 85 85 94
Student27 75 77 72 84 89 90 84
Student28 78 88 81 85 87 72 82
Student29 98 99 88 70 71 88 70
Student30 95 100 77 79 70 89 89
Student31 75 91 93 93 71 74 77
Student32 72 90 76 98 88 90 82
Student33 82 84 75 75 100 88 93
Student34 97 100 74 93 84 82 97
Student35 92 93 74 93 72 96 92
Student36 100 96 77 91 95 78 90
Student37 90 75 82 96 98 82 76
Student38 81 72 80 84 86 84 88
Student39 71 71 96 94 76 81 85
Student40 85 93 99 94 91 83 95
The next step is to create a function, calcaverage, to calculate the average grade for each student. I.e. there should be a display line of each student and their respective average of all of the test grades. I can't figure out how to properly create the 2D array, let alone get on to the average for each student.
This is what I have right now, but it's not working properly so any help would be greatly appreciated. Thanks in advance.
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
|
#include "pch.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int STUDENTS = 40, ASSIGNMENTS = 8, TOTAL = 350;
int main()
{
ifstream gradebook;
string filename, students[TOTAL];
int grades[ASSIGNMENTS][STUDENTS], i = 0;
cout << "Enter the filename:" << endl;
getline(cin, filename);
gradebook.open(filename);
int row, col;
for (row = 0; row < STUDENTS; row++)
for (col = 0; col < ASSIGNMENTS; col++)
gradebook >> grades[ASSIGNMENTS][STUDENTS];
gradebook.close();
return(0);
}
|