Skip to main content

Important Introduction to Programming Short Questions

Chapter: 44
Question 1:
What does ifstream & operator >> accomplish for a Matrix?
Answer: It reads matrix data from an input file stream by calling the matrix's input function.
Chapter: 44
Question 2:
How does the transpose method affect a matrix?
Answer: It swaps the rows and columns of the matrix, effectively flipping it over its diagonal.
Chapter: 44
Question 3:
What is the result of adding a matrix to itself with an additional constant?
Answer: The matrix is added to itself and then the constant is added to each element of the resulting matrix.
Chapter: 44
Question 4:
How does operator += differ from operator + in the Matrix class?
Answer: operator += updates the current matrix with the result of addition, while operator + creates a new matrix with the result.
Chapter: 44
Question 5:
What is the effect of subtracting one matrix from another using operator -?
Answer: It generates a new matrix where each element is the result of subtracting elements of the second matrix from the corresponding elements of the first matrix.
Chapter: 44
Question 6:
Explain the purpose of Matrix::operator * (double d) in multiplication.
Answer: It multiplies each element of the matrix by the given double value and returns the updated matrix.
Chapter: 44
Question 7:
What does Matrix::operator / (double d) perform?
Answer: It divides each element of the matrix by the given double value and returns the updated matrix.
Chapter: 45
Question 8:
What role does the assignment operator play in matrix class operations?
Answer: The assignment operator handles dynamic memory allocation for matrices, ensuring correct memory management when matrices of different sizes are assigned.
Chapter: 45
Question 9:
Why is the assignment operator defined to return a constant reference to a matrix?
Answer: It allows chaining assignments (e.g., a = b = c) and ensures that the returned reference cannot be modified, enhancing safety and efficiency.
Chapter: 45
Question 10:
How does the assignment operator handle self-assignment?
Answer: It checks if the object being assigned to is the same as the object being assigned from, to avoid issues like deleting and reusing the same memory.