Engineering Problem Solving With C++, 3e Chapter 8 Test Bank

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

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

// Function prototype to print a two dimensional 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

// Invoke function to print the values 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

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


Engineering Problem Solving with C++, 3e Chapter 8 Test Bank

Use the following two matrices in answering questions 2 through 4


Matrix A Matrix B
42 25 16 3 12 7
31 10 28 22 4 30
6 14 39 15 9 27
11 9 26 8 16 13

2. Calculate A-B . (Matrix subtraction)


3. Calculate the transpose of matrix A.

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


Engineering Problem Solving with C++, 3e Chapter 8 Test Bank

4. Show the output of the following loops.


for (L=3; L >=0; L--)
{ for (M=0; M < 2; M++)
cout << B[L][M] << " ";
cout << endl;
}
5. Solve the following set of simultaneous linear equations using Gaussian Elimination.
x - y + 3z = 7
3x + 2y – z = 11
2x – y + z = 3

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


Engineering Problem Solving with C++, 3e Chapter 8 Test Bank

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

6. The value of Arr[1][3] is:


A. 3
B. 4
C. 8
D. 57
7. Which of the following statements would properly declare this two-dimensional array in
C++?
A. int Arr[4][5];
B. int Arr[3][4];
C. int Arr[5][4];
D. int Arr[4][3];
8. Which of the following statements is the proper function prototype for a function that will
print this array?
A. void PrintIt(const int array[][], int rows, int columns);
B. void PrintIt(const int array[4][], int rows, int columns);
C. void PrintIt(const int array[][5], int rows, int columns);
D. void PrintIt(const int array, int rows, int columns);
9. Which of the following statements will properly invoke the function PrintIt?
A. PrintIt (Arr[4][5], 4, 5);
B. PrintIt (Arr[][], 4, 5);
C. PrintIt (Arr, 5, 4);
D. PrintIt (Arr, 4, 5);

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


Engineering Problem Solving with C++, 3e Chapter 8 Test Bank

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

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


Engineering Problem Solving with C++, 3e Chapter 8 Test Bank

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

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


Engineering Problem Solving with C++, 3e Chapter 8 Test Bank

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

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.

You might also like