Professional Documents
Culture Documents
Engineering Problem Solving With C++, 3e Chapter 8 Test Bank
Engineering Problem Solving With C++, 3e Chapter 8 Test Bank
Engineering Problem Solving With C++, 3e Chapter 8 Test Bank
1. Write code requested by the comments which are given in bold. Be sure to use pass by
reference and use the const modifier where appropriate.
#include <iostream>
using namespace std;
const ROW_SIZE = 4;
const COL_SIZE = 3;
// Function prototype for function that adds a specified value to every
// value stored in an array
int main()
{ int myArray[ROW_SIZE][COL_SIZE] = {{2,4,6},{1,8,10},{3,5,7},[9,11,13}};
int value;
cout << "Enter the value to add to each element: ";
cin >> value;
// Invoke function to add value to every value stored in myArray
return 0;
}
// (Function definition for function that adds a specified value to every value in an array
// (Function definition for function to print values stored in a two dimensional array
Use the following two-dimensional array named Arr to answer questions 6 through 9.
16 22 8 31 45
11 35 27 3 60
4 18 39 51 48
13 57 36 26 5
10. Which of the following for loops will print the column whose subscript is 1 in order (i.e.
from top to bottom)
A. for (int J = 0; J < 5; J++)
cout << MyArray[J][1] << ' ';
B. for (int J = 4; J >= 0; J--)
cout << MyArray[J][1] << ' ';
C. for (int J = 4; J >= 0; J--)
cout << MyArray[1][J] << ' ';
D. for (int J = 0; J < 5; J++
cout << MyArray[1][J] << ' ';
11. Given the two-dimensional array declared by the following statement
int myArray[4][3] = {{2,4,6},{1,8,10},{3,5,7},[9,11,13}};
what is the value of myArray[1][2]
A. 4
B. 5
C. 8
D. 10
12. Which of the following is the formula for the determinant of a two by two matrix?
A. A1 1 * A1 2 - A 2 1 * A2 2
B. A1 1 * A2 2 - A 1 2 * A2 1
C. A1 1 * A1 2 + A 2 1 * A2 2
D. A1 1 * A2 2 + A 1 2 * A2 1
13. When calculating the product of two matrices (A x B) where the following declarations
define the size of A and B, which of the declarations correctly defines matrix C to hold the
result.
double A[3][4], B[4][2];
A. double C[4][4];
B. double C[3][4];
C. double C[4][2];
D. double C[3][2];
E. The product A x B can not be computed.
14. Which of the following lines represent the same line as the equation 2y + 6x = 12
A. 2 – x = y
B. y -6 = 3x
C. 6 = 3x + y
D. None of the above are the same line as the given equation
15. The first subscript in a two-dimensional array in C++ refers to the number of columns.
A. True
B. False
16. When calculating the sum of two matrices (Matrix Addition) the two matrices must be square
matrices, i.e. the number of row is the same as the number of columns?
A. True
B. False
17. When calculating the product of two matrices (Matrix Multiplication) the number of columns
in the first matrix must be the same as the number of rows in the second matrix.
A. True
B. False
18. It is recommended that the sizes of multidimensional arrays be declared constants, since this
will facilitate the changing of the size of the array for the next execution of the program if
needed.
A. True
B. False
19. Determinants can only be calculated for a square matrix.
A. True
B. False
20. The equation 6x - 3y -2z = 7 is a linear equation.
A. True
B. False
21. A plane is specified by a linear equation in two variables
A. True
B. False
22. A nonsingular system of equations is a system of equations that does not have a point as a
solution.
A. True
B. False
23. Gaussian Elimination is a method for solving systems of linear equations, by first eliminating
a variable from all but one equation, then eliminating another variable from all but two
equations, continuing until one equation has only one variable, and then performing back
substitution.
A. True
B. False
24. A system of simultaneous linear equations is ill-conditioned if when solving the system using
Gaussian Elimination an equation has all coefficients become zero or very close to zero.
A. True
B. False
25. The process of pivoting in Gaussian Elimination never results in more accuracy, only in
simpler hand calculations.
A. True
B. False
26. All column dimensions for 2D arrays must be specified when passing them as parameters.
A. True
B. False
27. If the pre-conditions of a function are not met, the function is still expected to work correctly.
A. True
B. False
28. Post-conditions describe the changes that will be made to the arguments during the execution
of the function.
A. True
B. False
29. The STL vector class may be used as a generic implementation of the array concept.
A. True
B. False
30. All column dimensions for higher dimensional arrays except the left-most must be specified
when passing them as parameters.
A. True
B. False