Important Introduction to Programming Short Questions
Chapter: 44
Question 1:
What is the purpose of the transpose() function in the Matrix class?
Answer:
The transpose() function interchanges rows and columns of the matrix. For a square matrix, it swaps elements in place; for non-square matrices, it creates a new matrix with swapped dimensions.
Chapter: 44
Question 2:
What does the input(ifstream &is) function read from a file?
Answer:
The input(ifstream &is) function reads the number of rows and columns from the file, followed by the matrix elements, and populates the matrix.
Chapter: 44
Question 3:
What is the significance of os.setf(ios::fixed,ios::floatfield) in the output(ostream &os) function?
Answer:
It sets the output to fixed-point notation for floating-point numbers, ensuring consistent decimal formatting.
Chapter: 44
Question 4:
Why does the transpose() function use a temporary variable of type double?
Answer:
The temporary variable is used to swap elements when transposing a square matrix to avoid overwriting data before it's swapped.
Chapter: 44
Question 5:
What happens if the dimensions in the input(ifstream &is) function are not greater than zero?
Answer:
If the dimensions are not greater than zero, the function does not perform any operations and the matrix remains unchanged.
Chapter: 44
Question 6:
How does the transpose() function handle non-square matrices?
Answer:
For non-square matrices, the transpose() function creates a new matrix with swapped dimensions, copies the elements, and assigns the new matrix to the current one.
Chapter: 44
Question 7:
What is the role of *this = temp in the transpose() function?
Answer:
*this = temp assigns the transposed matrix (temp) to the current matrix, updating its values and dimensions.
Chapter: 44
Question 8:
What does the Matrix::Matrix(const Matrix &m) constructor do?
Answer:
The copy constructor initializes a new matrix as a copy of another matrix m, copying all elements.
Chapter: 44
Question 9:
What does the destructor Matrix::~Matrix() do?
Answer:
The destructor deallocates the memory used by the matrix elements to prevent memory leaks.
Chapter: 44
Question 10:
How are matrix elements initialized in the default constructor?
Answer:
In the default constructor, all matrix elements are initialized to zero.