#include <iostream> #include <fstream> using namespace std; int main () { int height, width; int sum,row,column,value; int **array; ifstream inFile("matrix1.dat"); if(!inFile) { cerr << "File matrix1.dat could not be opened!"; } inFile >> height >> width; cout << height << ' '<< width << endl; **array = &array[height][width]; while(inFile) { inFile >> row >> column >> value; array[row][column] = value; } //calculate the sum of each row for (int i=0; i<height; i++) { sum = 0; for (int j=0; j<width; j++) { sum += array[i][j]; } cout << i << " = " << sum << endl; } //calculate the sum of each column for (int i = 0; i < width; i++) { sum = 0; for (int j = 0; j < height; j++) { sum += array[j][i]; } cout << i << " = " << sum << endl; } for (int i = 0; i < height; i++){ delete[] array[i]; delete[] array; } } |