COSC6000 Homework 08

$30.00

Category: Tags: , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (3 votes)

Develop a function that defines a 2­dimensional array of type ‘double’. Also develop a function to destroy the array. Two functions should make following test code to work. // test routine int main(int argc, const char * argv[]) { const int size1 = 3; const int size2 = 4; double *vect; double **mat2d = makeDoubleArray2D(vect,size1,size2); // set for (int i = 0 ; i < size1 ; i++){ for (int j = 0 ; j < size2 ; j++){ mat2d[i][j] = static_cast(i + 1) / (j + 1); } } // print std::cout << “matrix\n”; std::cout.setf(std::ios::scientific); std::cout.precision(2); for (int i = 0 ; i < size1 ; i++){ for (int j = 0 ; j < size2 ; j++){ std::cout << std::setw(9) << mat2d[i][j]; } std::cout << std::endl; } std::cout << “vector\n”; for (int i = 0 ; i < size1 * size2 ; i++){ std::cout << vect[i] << std::endl; } destroyDoubleArray2D(vect,mat2d); return 0; } Example output: matrix 1.00e+00 5.00e-01 3.33e-01 2.50e-01 2.00e+00 1.00e+00 6.67e-01 5.00e-01 4/23/2018 Homework 08 https://tulane.instructure.com/courses/2165899/assignments/13467400 2/2 3.00e+00 1.50e+00 1.00e+00 7.50e-01 vector 1.00e+00 5.00e-01 3.33e-01 2.50e-01 2.00e+00 1.00e+00 6.67e-01 5.00e-01 3.00e+00 1.50e+00 1.00e+00 7.50e-01 As you see in the code, it assigns numbers to mat2d[i][j], but doesn’t assign anythig to vect[i]. As you see in the example output, ‘mat2d’ and ‘vect’ have same values; ‘vect’ is a reshaped array of ‘mat2d’ in row­order. This is because ‘mat2d’ and ‘vect’ share a same memory block. Your function, makeDoubleArray2D() should previde this mechanism. Your function, destroyDoubleArray2D() frees the arrays allocated by makeDoubleArray2D().