#include <iostream>
#include <fstream>
using namespacee std;
 
int** createArray(int rows, int cols);
void readData(int** dataArray, ifstream& file_in, int rows, int cols);
void queryData(int** dataArray);
char command();
 
int main()
{
        const int ROWS = 10;
        const int COLS = 10;
 
        int **grades = createArray(ROWS, COLS);
 
        ifstream fin("grades.txt");
        if (!fin)
        {
               cout << "* ERROR * unable to open file (grades.txt)" <<endl;
               exit(0);
        }
 
        readData(grades, fin, ROWS, COLS);
 
        do
        {
               queryData(grades);
        } while (command() != 'Q');
 
        return 0;
}
 
int** createArray(int rows, int cols)
{
        int** dataArray = new int*[rows];
        for (int i = 0; i < rows; i++)
        {
               dataArray[i] = new int[cols];
        }
        return dataArray;
}
 
void readData(int** dataArray, ifstream& file_in, int rows, int cols)
{
        for (int i = 0; i < rows; i++)
        {
               for (int j = 0; j < cols; j++)
               {
                       file_in >> dataArray[i][j];
               }
        }
}
 
void queryData(int** dataArray)
{
        int student, assignment;
 
        cout << "Enter student number [0..9]: ";
        cin >> student;
        cout << "Enter assignment number [0..9]: ";
        cin >> assignment;
 
        cout << "Grade was " << dataArray[student][assignment] <<endl;
}
 
char command()
{
        char response;
        do
        {
               cout << "Enter (Q)uit or (V)iew: ";
               cin >> response;
        } while (response != 'Q' && response != 'V');
 
        return response;
}
 
 

syntax highlighted by Code2HTML, v. 0.9.1