Read the given below code and explain what task is being-00990
This subjective question is related to the book/course vu cs605 Software EngineeringII. It can also be found in vu cs605 Mid Term Solved Past Paper No. 1.
Question 1: Read the given below code and explain what task is being performed by this function
Matrix :: Matrix ( int row , int col ) {
numRows = row ;
numCols = col ;
elements = new ( double * ) [ numRows ] ;
for ( int i = 0 ; i < numRows ; i ++ ) {
elements [ i ] = new double [ numCols ] ;
for ( int j = 0 ; j < numCols ; j ++ )
elements [ i ] [ j ] = 0.0 ;
}
}
Hint : This function belong to a matrix class, having
Number of Rows = numRows
Number of Columns = numCols
Matrix :: Matrix ( int row , int col ) {
numRows = row ;
numCols = col ;
elements = new ( double * ) [ numRows ] ;
for ( int i = 0 ; i < numRows ; i ++ ) {
elements [ i ] = new double [ numCols ] ;
for ( int j = 0 ; j < numCols ; j ++ )
elements [ i ] [ j ] = 0.0 ;
}
}
Hint : This function belong to a matrix class, having
Number of Rows = numRows
Number of Columns = numCols
Answer:
In the above mentioned code, first of all programmer call the constructor who have two parameters for the number of rows & columns in the matrix. Then this constructor also dynamically allocates the memory for the elements of the matrix & also initializes the value of the all elements of matrix with 0.0