#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int grade;
const int numGrades = 5;
const int numStudents = 5;
float student_total;
char choice;
int gradeArray[numStudents] [numGrades];
for (int row=0; row < numStudents; row++)
{
cout << "\n*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*\n";
for (int col=0; col < numGrades; col++)
{
cout << "Enter grade #" << col +1 << " for student " << row +1 << endl;
cout << "\n\tEnter a grade:";
cin >> grade;
gradeArray[row][col] = grade;
}
} cout << "\n*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*\n";
cout << "Here are the grades for your students, and their averages:\n";
for (row=0; row < numStudents; row++)
{
student_total =0;
cout << "Student #: " << row+1 << "\t";
for ( int col=0; col < numGrades; col++)
{
cout << gradeArray[row][col]<< "\t";
student_total = student_total + gradeArray[row][col];
}
cout << student_total / numGrades;
cout << endl;
}
cout << "Would you like to save this data to disk?\n";
cin >> choice;
if (choice =='Y' || choice =='y')
{
cout <<"Write to disk.....";
ofstream outfile ("grade_data.dat", ios::binary);
for (row=0; row < numStudents; row++)
{
for ( int col=0; col < numGrades; col++)
{
outfile.put(gradeArray[row][col]);
}
}
cout << "File written...filename: grade_data.dat\n";
}
return 0;
}