Engineering Problem Solving with C++, 3e Chapter 6 Test Bank
1. What is the output from the following program
#include <iostream >
using namespace std;
int X{6}, C{3};
int TestMe(int &Y, int Z);
int main ()
{
int A, B, W;
A = 5;
B = 2;
X = 1;
W = TestMe(A, B);
// Last two output lines
cout << “A = ” << A << ” B = ” << B << endl;
cout << “X= ” << X<< ” C = ” << C << endl;
return 0;
}
int TestMe (int &Y, int Z)
{
int C;
cout << “Y = ” << Y <<” Z = ” << Z << endl;
cout << “C = ” << C << endl;
cout << “X = ” << X << endl;
Z = 7;
X = C + Z;
Y = X + Z;
cout << “X = ” << X <<” Z = ” << Z << endl;
cout << “Y = ” << Y << endl;
return Z;
}
2. Write a function that will calculate the length of the hypotenuse of a right triangle. The
function will take two real number parameters for the other two sides of the right triangle.
The function will return the result it computes.
3. What is the output of the following program?
#include <iostream>
using namespace std;
void TestIt(int Y);
int main ()
{
int A, B;
A = 5;
TestIt(A);
B = 3;
TestIt(B);
return 0;
}
void TestIt (int Y)
{
int Z(7);
static int X(2);
Z= Y*3 – Z;
Y = Y * 2;
X ++;
cout << “X = ” << X << ” Y = ” << Y << ” Z = ” << Z << “\n\n” ;
return;
4. In C++, pass by reference for an integer parameter can be achieved …
5. The argument for a parameter which is pass by value …
6. The argument and the parameters of a function
7. Which of the following is not true when using functions to create a modular solution.
8. The key word “static” is used to declare a variable when you want the variable …
9. Which of the following is a storage class?
10. The scope of a variable refers to …
11. Which of the following is the scope of a variable which is declared outside of the main
program?
12. In the following function prototype:
Engineering Problem Solving with C++, 3e Chapter 6 Test Bank
14. Which of the following statements properly invokes the random number generator storing the
resulting random number into myNumber.
15. A good way to assure that the random number generator will not give the same sequence of
random numbers each time your program is run is to
16. The incremental search method for finding the root of an equation requires that the two
guesses , a and b, at the root, satisfy the following criteria
17. If a variable which is declared to be an integer is passed by value to a parameter which is
declared to be a double, an error message will occur at compile time.
19. Constants that are declared to be global are available throughout the program in the main
20. The NewtonRaphson method algorithm for locating the root of a function is guaranteed to
locate a root in a known number of iterations.
21. A better approximation of the area under a function is obtained by decreasing the number of
trapezoids used.
22. When a local variable in a function is declared using the automatic storage class, the variable
will retain its value from one invocation of the function to the next.
23. The public interface of a well-defined data type provides a complete set of public methods
24. The objective of encapsulation is to increase the transparency of how objects are
implemented.
25. Which methods are typically value-returning methods with no parameters, whose purpose is
D. None of these.
26. Which methods are typically void methods with one or more input parameters, whose
27. It is impossible to predict the sequence of random numbers produced by a random number
generators.