Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 44
Q681:
What is the role of the destructor in the Matrix class?
A. To allocate memory for the matrix elements.
B. To deallocate memory that was allocated using the new operator.
C. To initialize matrix elements to zero.
D. To copy matrix data from one object to another.
Correct Answer:
B
Chapter: 44
Q682:
Which of the following functions is used to get the number of columns in a Matrix object?
A. int getCols(void)
B. void getCols(void)
C. int getRows(void)
D. void getRows(void)
Correct Answer:
A
Chapter: 44
Q683:
How is dynamic memory allocated for the matrix elements in the Matrix class constructor?
A. Using the malloc function.
B. By declaring a static array.
C. Using the new operator to allocate an array of pointers and then allocating arrays for each pointer.
D. By using a vector of vectors.
Correct Answer:
C
Chapter: 44
Q684:
What does the copy constructor of the Matrix class do?
A. Initializes a new Matrix object with the same values as an existing Matrix object.
B. Deallocates memory used by an existing Matrix object.
C. Initializes the matrix with default values.
D. Allocates memory for a new Matrix object and sets it to null.
Correct Answer:
A
Chapter: 44
Q685:
Which operator function allows multiplying a matrix by a double value?
A. Matrix operator * (double d) const;
B. Matrix operator * (const Matrix &m);
C. friend Matrix operator * (double d, Matrix &m);
D. Matrix operator * (Matrix &m) const;
Correct Answer:
A
Chapter: 44
Q686:
What is the purpose of the friend function operator + (double d, Matrix &m)?
A. To add a double value to a matrix when the double is on the left-hand side.
B. To add two matrices together.
C. To multiply a matrix by a double value.
D. To transpose the matrix.
Correct Answer:
A
Chapter: 44
Q687:
What does the transpose function do in the Matrix class?
A. Returns a new Matrix object that is the transpose of the current matrix.
B. Adds two matrices together.
C. Initializes the matrix with zeros.
D. Multiplies the matrix by a double value.
Correct Answer:
A
Chapter: 44
Q688:
How does the Matrix class handle input from a file?
A. It uses the input function with ifstream as a parameter.
B. It uses the input function with istream as a parameter.
C. It uses the output function with ifstream as a parameter.
D. It uses the output function with ostream as a parameter.
Correct Answer:
A
Chapter: 44
Q689:
What ASCII value is used to print the graphic symbol in the left corner?
A. 218
B. 191
C. 179
D. 192
Correct Answer:
A
Chapter: 44
Q690:
What does os << (char) 218; do in the code?
A. Outputs a character
B. Outputs an integer
C. Outputs a string
D. Outputs a floating-point number
Correct Answer:
A
Chapter: 44
Q691:
What is the width set for the columns in the matrix display?
A. 8
B. 10
C. 12
D. 14
Correct Answer:
B
Chapter: 44
Q692:
What type of matrix does the code deal with?
A. Integer
B. Float
C. Double
D. Char
Correct Answer:
C
Chapter: 44
Q693:
Which function is used to avoid scientific notation in output?
A. os.setf(ios::showpoint)
B. os.setf(ios::fixed,ios::floatfield)
C. os << setw(10)
D. os << setprecision(2)
Correct Answer:
B
Chapter: 44
Q694:
What does the Matrix::output function do?
A. Inputs matrix values
B. Outputs matrix with graphics
C. Transposes the matrix
D. Multiplies matrices
Correct Answer:
B
Chapter: 44
Q695:
What must be output before the matrix values when saving to a file?
A. Matrix type
B. Matrix size (rows and columns)
C. Matrix elements
D. None of the above
Correct Answer:
B
Chapter: 44
Q696:
What function is responsible for reading a matrix from a file?
A. input(ifstream &is)
B. input(istream &is)
C. output(ofstream &os)
D. transpose()
Correct Answer:
A
Chapter: 44
Q697:
What condition is checked first in the transpose() function?
A. Number of elements
B. Matrix type
C. Square matrix (rows = columns)
D. Matrix dimensions
Correct Answer:
C
Chapter: 44
Q698:
What happens if the matrix is not square in the transpose() function?
A. An error is thrown
B. A temporary matrix is created
C. The transpose is skipped
D. The matrix is resized
Correct Answer:
B
Chapter: 44
Q699:
What is returned by the transpose() function?
A. The original matrix
B. A copy of the original matrix
C. A reference to the transposed matrix
D. Nothing
Correct Answer:
C
Chapter: 44
Q700:
Which operator is overloaded to handle matrix assignment?
A. +
B. -
C. =
D. *
Correct Answer:
C