Question: C++ Matrix given input.text using common read file. ( not using file.open( input.text );.....Using run configurations common input File.) 4 4 6 0 2 1
C++
Matrix given input.text using common read file. ( not using file.open( "input.text ");.....Using run configurations common input File.)
4 4 6 0 2 1 0 3 1 1 1 1 2 3 1 3 1 4 output : matrix: 0 0 1 0 0 1 0 0 0 0 0 1 0 4 0 0 rowPosition : 0 1 2 3 Note that rowPtr[0] = 0 indicates that the values in row 0 of the matrix start at index position 0 of the value array. rowPtr[1] = 1 indicates that the values in row 1 of the matrix start at index position 2 of the value array ______________________________________ Class int n; //The number rows of the original matrix int m; //The number of columns of the original matrix int nonZeros; //The number of non-zeros in the original matrix int* values; //value array assuming all are integers int* rowPtr; //Array that contains number of non-zero elements in each row of the original matrix
void:AddRow(){ //code here print out rowPosition as output above. } int main(){
int numRows, numColumns, numNonZeros;
int row, col, value;
//read in the first matrix
cin >> numRows >> numColumns;
cin >> numNonZeros;
A = new CSR (numRows, numColumns, numNonZeros);
for (int i=0; i < numNonZeros; i++) {
cin >> row >> col >> value;
(*A).addValue (value);
(*A).addRow (row);//needs to be done cleverly in the method
(*A).addColumn (col);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
