Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
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.
View Answer
B
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)
View Answer
A
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.
View Answer
C
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.
View Answer
A
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;
View Answer
A
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.
View Answer
A
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.
View Answer
A
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.
View Answer
A
Q689: What ASCII value is used to print the graphic symbol in the left corner?
- A: 218
- B: 191
- C: 179
- D: 192
View Answer
A
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
View Answer
A