Problem Solving with C++ 9th Edition Walter Savitch – Test Bank

$20.00

Pay And Download

 

Complete Test Bank With Answers

 

 

 

Sample Questions Posted Below

 

 

 

 

TRUE/FALSE

  1. A void function can return any value

ANSWER: FALSE

  1. A void function can be used in an assignment.

ANSWER: FALSE

  1. A void function may not be used in an output statement.

ANSWER: TRUE

  1. Functions can return at most one value.

ANSWER: TRUE

  1. The following is legal in a void function

return;

ANSWER: TRUE

  1. In a function with call-by-reference parameters, the values of the actual arguments are passed to the function.

ANSWER: FALSE, The actual variables (or more precisely their memory addresses) are passed.

  1. In a function with call-by-reference parameters, any changes to the formal parameters will change the actual arguments passed to the function.

ANSWER: TRUE

  1. It is acceptable to have both call-by-value and call-by-reference parameters in the same function declaration.

ANSWER: True

  1. It is illegal to call other functions from inside a function definition.

ANSWER: FALSE

  1. A stub is a function that is completely defined and well tested

ANSWER: FALSE

 

SHORT ANSWER

  1. A ___________ is a main program that only checks that functions execute correctly.

ANSWER: driver

  1. The values or variables listed in the function declaration are called _________ to the  function.

ANSWER: (formal) parameters

  1. Given the following function definition fragment, for which values of myInt should the function be tested?

int doSomething(int myInt)

{

if(myInt < 0)

{

//do some stuff here

}

}

ANSWER: -1, 0,1

  1. When the address of the actual argument is passed to the formal parameter, this is called __________________________

ANSWER: call-by-reference –or- pass-by-reference

  1. If we want to test if a given function works correctly, we would write a _________ to test it.

ANSWER: driver

  1. The variables passed a function are called _________.

ANSWER: arguments

  1. What is the correct way to call the following function? _________________________

void setDisplay();

ANSWER: setDisplay();

  1. A function that does not return a value is known as a ________ function.

ANSWER: void

  1. What type of value does a void function return? ____________

ANSWER: nothing

  1. What symbol is used to signify that a parameter is a reference parameter? ______

ANSWER: ampersand (&)

  1. What is the correct way to call the following function? Assume that you have two variables named intArgument (int) and floatArgument(float).

void doThings(float x, int y);

ANSWER: doThings(floatArgument, intArgument);

  1. Using functions in a program is called _____________.

ANSWER: procedural abstraction

  1. pre and post conditions for a function should be written (before/after) the function definition is written.

ANSWER: before

  1. A ________ is a simplified version of a function used to test the main program.

ANSWER: stub

  1. Testing a program with values that are close to values that will change the execution of a program is called _________________.

ANSWER: boundary testing

MULTIPLE CHOICE

  1. Which of the following is a legal call to the displayOutput function?

void displayOutput(int total);

    1. void displayOutput(myTotal);
    2. displayOutput(int mytotal);
    3. displayOutput(myTotal);
    4. cout << displayOutput(myTotal);

ANSWER: C

  1. The precondition(s) for a function describe:
    1. What is true after the function is executed
    2. What the function does
    3. How to call the function
    4. What must be true before the function executes

ANSWER: D

  1. Which of the following is true for a void function?
    1. There cannot be a return statement.
    2. The value of void should be returned.
    3. The value of 0 should be returned.
    4. Nothing is returned.

ANSWER: D

  1. Call-by-reference parameters are passed
    1. nothing
    2. the actual argument.
    3. the value in the actual argument.
    4. the address of the argument.

ANSWER: B

  1. If you need a function to get both the number of items and the cost per item from a user, which would be a good function declaration to use?
    1. int,float getData();
    2. int getData(float cost);
    3. void getData(int count, float cost);
    4. void getData(int& count, float& cost);

ANSWER: D

  1. What is the output of the following function and function call?

void calculateCost(int count, float& subTotal, float& taxCost);

 

float tax = 0.0,

subTotal = 0.0;

 

calculateCost(15, subTotal,tax);

cout << “The cost for 15 items is ” << subtotal

<< “, and the tax for ” << subTotal << ” is ” << tax << endl;

//end of fragment

 

void calculateCost(int count, float& subTotal, float& taxCost)

{

if ( count < 10)

{

subTotal = count * 0.50;

}

else

{

subTotal = count * 0.20;

}

taxCost = 0.1 * subTotal;

}

    1. The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;
    2. The cost for 15 items is 0.00, and the tax for 3.00 is 0.00;
    3. The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;
    4. The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;

ANSWER: A

  1. What is the output of the following function and function call?

void calculateCost(int count, float& subTotal, float taxCost);

 

float tax = 0.0,

subtotal = 0.0;

 

calculateCost(15, subtotal,tax);

cout << “The cost for 15 items is ” << subtotal

<< “, and the tax for ” << subtotal << ” is ” << tax << endl;

//end of fragment

 

void calculateCost(int count, float& subTotal, float taxCost)

{

if ( count < 10)

{

subTotal = count * 0.50;

}

else

{

subTotal = count * 0.20;

}

taxCost = 0.1 * subTotal;

}

    1. The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;
    2. The cost for 15 items is 0.00, and the tax for 3.00 is 0.00;
    3. The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;
    4. The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;

ANSWER: D

  1. Which of the following function prototypes are not valid?
    1. void doSomething(int& x, int y);
    2. void doSomething( int& x, int& y);
    3. void doSomething( int x, int y);
    4. all are not valid
    5. all are valid

ANSWER: E

  1. You should make a parameter a reference parameter if:
    1. You need the function to change the value of the argument passed to the function.
    2. you need to be able to change the value of the parameter in the function, but not the value of the argument.
    3. Always.
    4. If any of the other parameters are reference parameters.

ANSWER: A

  1. Which of the following are true?
    1. a function can call another function.
    2. as long as the function is defined anywhere in your program, it can be used anywhere else.
    3. a function definition can contain another function definition.
    4. if you have function prototypes, the order in which you define your functions is important.

ANSWER: A

  1. The postcondition of a function
    1. determines how the function will complete its job.
    2. tells what must be true before the function executes.
    3. declares the function for the compiler.
    4. tells what will be true after the function executes.

ANSWER: D

  1. What is the value of choice after the following statements?

void getChoice(int& par_choice, in par_count);

int choice, count=3;

 

getChoice(choice, count);

 

void getChoice(int& par_choice, in par_count)

{

if(par_count<0)

par_choice =0;

if(par_count = 0)

par_choice=-1;

else

par_choice=99;

return;

}

    1. 3
    2. 0
    3. –1
    4. 99

ANSWER: D

  1. What is wrong with the following function body?

void calculate(int count, float price, float& cost)

{

if (count < 0)

cost=0.0;

else

cost=count*price;

return;

}

    1. void functions may not have a return statement.
    2. void functions must return a value
    3. nothing
    4. can not mix reference and value parameters

ANSWER: C

  1. If you were to write a function for displaying the cost of an item to the screen, which function prototype would be most appropriate?
    1. void display();
    2. void display(float myCost);
    3. int display (float myCost);
    4. float display();

ANSWER: B

  1. Given the function definition

    void something ( int a, int& b )
    {
    int c;
    c = a + 2;
    a = a * 3;
    b = c + a;
    }
    what is the output of the following code fragment that invokes something?
    (All variables are of type int.)
    r = 1;
    s = 2;
    t = 3;
    something(t, s);
    cout << r << ‘ ‘ << s << ‘ ‘ << t << endl;

    1. 1 14 3
    2. 1 10 3
    3. 5 14 3
    4. 1 14 9
    5. none of the above

ANSWER: A

  1. Given the following function declaration and local variable declarations, which of the following is not a correct function call?

 

int myInt;

float myFloat;

char ch;

void someFunction(int& first, float second, char third);

  1. someFunction(1, 2.0, ch);
  2. someFunction(myInt, myFloat, ch);
  3. someFunction(myInt, 2.0, ‘c’);
  4. someFunction(myInt, myFloat, ‘1’);

 

ANSWER: A

  1. Given the following function definition

void shift(int& a, int&b)

{

a=b;

b=a;

}

 

What is the output after the following function call?

int first=0, second=10;

shift(first, second);

cout << first <<” “<< second << endl;

    1. 0 10
    2. 10 0
    3. 0 0
    4. 10 10

ANSWER: D

  1. What is the output of the following code fragments?

int trial( int& a, int b)

{

if(b > a)

{

a=b;

return –a;

}

else

{

return 0;

}

}

 

float x=0, y=10,z;

z=trial(y,x);

cout << z << ” ” << x <<” ” << y << endl;

    1. –10 0 0
    2. 0 10 0
    3. 10 0 0
    4. 0 0 10

ANSWER: D

  1. When a void function is called, it is known as
    1. An output function.
    2. A returned value.
    3. An executable statement.
    4. A comment

ANSWER: C

  1. If a function needs to modify more than one variable, it must
    1. be pass by value
    2. be a void function
    3. return all values needed
    4. be a call by reference function

ANSWER: D

  1. In the following function, what is passed to the first parameter?

void f1( int& value1, int value2);

 

int x,y;

f1(x,y);

    1. The value of x
    2. nothing, it is a void function
    3. the value of y
    4. the variable x (or its memory location)

ANSWER: D

  1. Given the following function definitions and program fragments, what is the output?

 

void f1(int& z, int &q)

{

int temp;

temp=q;

q=z;

z=temp;

}

 

void f2( int& a, int& b)

{

if( a<b)

f1(a,b);

else

a=b;

}

 

int x=3, y=4;

f2(y,x);

cout << x <<” ” << y << endl;

 

    1. 3 3
    2. 4 3
    3. 3 4
    4. 4 4

ANSWER: A

  1. A simplified version of a function which is used to test the main program is called
    1. A stub
    2. Abstraction
    3. Polymorphism
    4. A driver

ANSWER: A

  1. A simplified main program used to test functions is called
    1. A stub
    2. Abstraction
    3. Polymorphism
    4. A driver

ANSWER: D

  1. Testing a function or program using test values that are at or near the values that change the outcome of the program is known as using
    1. parameters
    2. functional decomposition
    3. boundary values
    4. a black-box

ANSWER: C

  1. Call-by-reference should be used
    1. For all variables
    2. When the function needs to change the value of one or more arguments
    3. Never
    4. only in void functions

ANSWER: B

  1. Which of the following comments would be the best post-condition for this swap function void swap( int& left, int&right);
    1. //Postcondition: None
    2. //Postcondition: the values of left and right are exchanged.
    3. //Postcondition: left has the value of right
    4. //Postcondition: left and right are unchanged

ANSWER: B

  1. What is wrong with the following code?

int f1( int x, int y)

{

x = y * y;

return x;

 

int f2( float a, float& b)

{

if(a < b)

b = a;

else

a=b;

return 0.0;

}

}

    1. Neither function should return a value
    2. Function definitions may not be nested
    3. Both parameters to f2 should be pass-by reference
    4. in f2, a can not be assigned b.
    5. nothing is wrong

ANSWER: B

  1. If you write a function that should use call-by-reference, but forget to include the ampersand,
    1. The program will not compile
    2. The program will not link
    3. The program will not run without a run-time error
    4. The program will run with incorrect results
    5. It doesn’t matter

ANSWER: D

  1. Testing your program should be done
    1. As each function is developed
    2. At the end of the coding
    3. Only if there appear to be problems
    4. Only if your instructor requires it.

ANSWER: A

There are no reviews yet.

Add a review

Be the first to review “Problem Solving with C++ 9th Edition Walter Savitch – Test Bank”

Your email address will not be published. Required fields are marked *

Category:
Updating…
  • No products in the cart.