/********************************************
This program reads in grades from grades.txt,
which has 6 homework grades for 6 students.
The user then can query the program to
determine specific student/hw grades.
********************************************/
#include <iostream>
#include <fstream>
using namespace std;
/*******************************************
** MAIN
*******************************************/
int main()
{
// create an array
int rows = 6, cols = 6;
int** A = new int*[rows];
for(int i = 0; i < rows; i++)
A[i] = new int[cols];
// Read and store grade info
ifstream fin("grades.txt");
for(int s = 0; s < rows; s++)
for(int g = 0; g < cols; g++)
fin >> A[s][g];
// Answer the questions using the 2D array
char c;
while( cout << "(Q)uit or (V)iew? " && cin >> c && c != 'Q')
{
int sn, hw;
cout << "Student number [0..5]: ";
cin >> sn;
cout << "Homework number [0..5]: ";
cin >> hw;
// Note about how the code performs the indexing: A[sn][hw]
cout << "Grade was " << A[sn][hw] << endl;
}
for(int i=0; i < rows; i++)
delete [] A[i];
delete [] A;
return 0;
}