Important Introduction to Programming Short Questions
Chapter: 44
Question 1:
What happens if negative values are passed to the matrix constructor?
Answer:
The constructor does not explicitly handle negative values, but it's good practice to validate and ensure that the number of rows and columns is non-negative.
Chapter: 44
Question 2:
What is the use of istream and ifstream in the Matrix class?
Answer:
istream is used for reading matrix data from the keyboard, while ifstream is used for reading matrix data from a file.
Chapter: 44
Question 3:
How does the operator- function work for subtracting a matrix from a double?
Answer:
friend Matrix operator - (double d, Matrix & m) subtracts a matrix from a double value, with the double on the left side, and returns a new Matrix with the result.
Chapter: 44
Question 4:
What is the significance of using const in the member functions of the Matrix class?
Answer:
const indicates that the member function does not modify the state of the object, ensuring that the matrix remains unchanged during these operations.
Chapter: 44
Question 5:
How is memory deallocated in the Matrix destructor?
Answer:
Memory is deallocated using delete[] elements, which frees up the dynamically allocated memory for the matrix elements.
Chapter: 44
Question 6:
What does the getRows() function return?
Answer:
The getRows() function returns the number of rows in the matrix as an integer.
Chapter: 44
Question 7:
How does the output(ostream &os) function format the matrix?
Answer:
The output(ostream &os) function formats the matrix with ASCII characters for corners and borders, and displays elements with fixed decimal precision.
Chapter: 44
Question 8:
Why is (char) 218 used in the output(ostream &os) function?
Answer:
(char) 218 represents the top-left corner of the matrix, used for visual formatting.
Chapter: 44
Question 9:
What does the output(ofstream &os) function include in its output?
Answer:
The output(ofstream &os) function writes the number of rows, number of columns, and the matrix elements to a file, without graphical symbols.
Chapter: 44
Question 10:
How does the input(istream &is) function interact with the user?
Answer:
The input(istream &is) function prompts the user for matrix dimensions and values, reading from standard input with space as a delimiter.