#include #include using namespace std; int** createArray(int rows, int cols); void readData(int** dataArray, ifstream& file_in, int rows, int cols); // Prototypes for functions you will write void printOneGrade (int **grades, int rows, int cols, int student, int assignment); void printOneStudent (int **grades, int rows, int cols, int student); void printOneAssignment(int **grades, int rows, int cols, int assignment); int main() { // Constants -- to keep simple we assume 10 students and 12 assignments const int ROWS = 10; // number of students const int COLS = 12; // number of assignments // Create 2D array and read grades in // grades[i][j] will be grades of i'th student on j'th assignment int **grades = createArray(ROWS, COLS); ifstream fin("grades.txt"); if (!fin) { cout << "ERROR: could not open file grades.txt\n"; exit(1); } readData(grades, fin, ROWS, COLS); char ch; do { // Ask user what they want to know about int student, assignment; cout << "Enter student number [0.. " << ROWS-1 << "]: "; cin >> student; cout << "Enter assignment number [0.. " << COLS-1 << "]: "; cin >> assignment; // Print out different info about the student and assignment printOneGrade (grades, ROWS, COLS, student, assignment); printOneStudent (grades, ROWS, COLS, student); printOneAssignment(grades, ROWS, COLS, assignment); // Should we continue? cout << "Continue? (y/n) "; cin >> ch; } while (ch == 'y'); 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; } // Read data -- assumes each row of input is one student. Each column is an assignment 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]; } } } // Prints grade for the given student and assignment // e.g. "Grade for student 1 on assignment 3 is 74"; void printOneGrade (int **grades, int rows, int cols, int student, int assignment) { cout << "Grade for student " << student << " on assignment " << assignment << " is " << grades[student][assignment]; } // Prints all grades for the given student // e.g. "Grades for student 1 are: // 96 67 56 74 94 100 98 68 95 65 82 80" void printOneStudent (int **grades, int rows, int cols, int student) { int i; cout << "Grades for student " << student << " are: " << endl; for(i=0;i