Important Introduction to Programming Short Questions
Chapter: 45
Question 1:
What does the addition operator function ensure before performing matrix addition?
Answer:
It ensures that the matrices are conformable, meaning they have the same number of rows and columns before adding them element-by-element.
Chapter: 45
Question 2:
What is returned by the addition operator function after adding two matrices?
Answer:
A new matrix is returned with the result of the element-wise addition, while the original matrices remain unchanged.
Chapter: 45
Question 3:
How does the += operator function differ from the + operator in matrix operations?
Answer:
The += operator modifies the left-hand side matrix in place and returns a reference to it, while the + operator returns a new matrix without modifying the originals.
Chapter: 45
Question 4:
How does the overloaded + operator handle the addition of a double to a matrix?
Answer:
It creates a new matrix where each element of the original matrix is incremented by the double value, and returns this new matrix.
Chapter: 45
Question 5:
How is the addition of a double to a matrix handled when the double is on the left side?
Answer:
It is handled by a friend function that creates a new matrix by adding the double to each element of the matrix and returns the new matrix.
Chapter: 45
Question 6:
What is the purpose of the operator* function in matrix class?
Answer:
It performs matrix multiplication, creating a new matrix based on the product of the elements from the two matrices, ensuring they are conformable for multiplication.
Chapter: 45
Question 7:
How does matrix multiplication handle conformability?
Answer:
It checks if the number of columns in the first matrix equals the number of rows in the second matrix; if not, multiplication cannot be performed.
Chapter: 45
Question 8:
What precaution is taken when dividing a matrix by a double to avoid errors?
Answer:
The code checks for division by zero and returns the original matrix if the divisor is zero, instead of performing the division.
Chapter: 45
Question 9:
How are stream insertion and extraction operators used with matrices?
Answer:
They are overloaded to handle matrix input and output operations with streams, allowing for easy reading from and writing to streams like cin and cout.
Chapter: 45
Question 10:
What does the operator += function return after modifying the matrix?
Answer:
It returns a reference to the modified left-hand side matrix.