You are on page 1of 10

Test Bank for C++ Programming: From Problem Analysis to Program Design, 6th Edition – D.S.

Test Bank for C++ Programming: From Problem


Analysis to Program Design, 6th Edition – D.S.
Malik

To download the complete and accurate content document, go to:


https://testbankbell.com/download/test-bank-for-c-programming-from-problem-analysi
s-to-program-design-6th-edition-d-s-malik/

Visit TestBankBell.com to get complete for all chapters


Chapter 6: User-Defined Functions

TRUE/FALSE

1. Using functions greatly enhances a program’s readability because it reduces the complexity of the
function main.

ANS: T PTS: 1 REF: 336

2. Once you write and properly debug a function, you can use it in the program (or different programs)
again and again without having to rewrite the same code repeatedly.

ANS: T PTS: 1 REF: 340

3. If the formal parameter list of a function is empty, the parentheses after the function name are not
needed.

ANS: F PTS: 1 REF: 344

4. The following function heading in a C++ program is valid:

int funcExp(int u, char v, float g)

ANS: T PTS: 1 REF: 344

5. The data type of a variable in a return statement must match the function type.

ANS: T PTS: 1 REF: 344

6. The execution of a return statement in a user-defined function terminates the program.

ANS: F PTS: 1 REF: 345

7. In C++, a function prototype is the function heading without the body of the function.

ANS: T PTS: 1 REF: 348

8. Assume that all variables are properly declared. The following statement in a value-returning function
is legal.

if (x % 2 == 0)
return x;
else
return x + 1;

ANS: T PTS: 1 REF: 351

9. The following return statement returns the value 10.

return 10, 16;

ANS: F PTS: 1 REF: 351


10. The function main is always compiled first, regardless of where in the program the function main is
placed.

ANS: F PTS: 1 REF: 361

MULTIPLE CHOICE

1. The standard header file for the abs(x)function is ____.


a. <cmath> c. <cctype>
b. <ioinput> d. <cstdlib>
ANS: A PTS: 1 REF: 337

2. To use the predefined function tolower, the program must include the header file ____.
a. <cctype> c. <cmath>
b. <iostream> d. <cstdlib>
ANS: A PTS: 1 REF: 338

3. The output of the statement:

cout << tolower('$') << endl;

is ____.

a. '$'
b. '0'
c. '1'
d. An error, because you cannot use tolower with '$'.
ANS: A PTS: 1 REF: 338

4. Assume the following.

static_cast<int>('a') = 97
static_cast<int>('A') = 65

The output of the statement:

cout << static_cast<int>(tolower('B')) << endl; is ____.


a. 65 c. 96
b. 67 d. 98
ANS: D PTS: 1 REF: 338

5. The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____.
a. 11.0 c. 13.0
b. 12.0 d. 14.0
ANS: D PTS: 1 REF: 338

6. The output of the statement:


cout << pow(2.0, pow(3.0, 1.0)) << endl;

is ____.

a. 6.0 c. 8.0
b. 7.0 d. 9.0
ANS: C PTS: 1 REF: 338

7. Functions that do not have a return type are called ____ functions.
a. zero c. void
b. null d. empty
ANS: C PTS: 1 REF: 341

8. The heading of the function is also called the ____.


a. title c. function head
b. function signature d. function header
ANS: D PTS: 1 REF: 341

9. A variable or expression listed in a call to a function is called the ____.


a. formal parameter c. data type
b. actual parameter d. type of the function
ANS: B PTS: 1 REF: 342

10. A variable listed in a header is known as a(n) ____ parameter.


a. actual c. formal
b. local d. function
ANS: C PTS: 1 REF: 342

11. Given the following function:

int next(int x)
{
return (x + 1);
}

what is the output of the following statement?

cout << next(next(5)) << endl;

a. 5 c. 7
b. 6 d. 8
ANS: C PTS: 1 REF: 347-348

12. Which statement below about prototypes and headers is true?


a. Parameter names must be listed in the prototype, but not necessarily in the header.
b. Prototypes end with a semicolon, but headers do not.
c. Headers should come before prototypes.
d. Headers end with a semicolon, but prototypes do not.
ANS: B PTS: 1 REF: 349
13. Given the following function prototype: int test(float, char);, which of the following
statements is valid?
a. cout << test(12, &);
b. cout << test("12.0", '&');
c. int u = test(5.0, '*');
d. cout << test('12', '&');
ANS: C PTS: 1 REF: 349

14. A function prototype is ____.


a. a definition, but not a declaration c. a declaration, but not a definition
b. a declaration and a definition d. a comment line
ANS: C PTS: 1 REF: 349

15. Given the following function prototype: double tryMe(double, double);, which of the
following statements is valid? Assume that all variables are properly declared.
a. cin >> tryMe(x);
b. cout << tryMe(2.0, 3.0);
c. cout << tryMe(tryMe(double, double), double);
d. cout << tryMe(tryMe(float, float), float);
ANS: B PTS: 1 REF: 349-350

16. Given the function prototype: double testAlpha(int u, char v, double t); which of
the following statements is legal?
a. cout << testAlpha(5, 'A', 2);
b. cout << testAlpha( int 5, char 'A', int 2);
c. cout << testAlpha('5.0', 'A', '2.0');
d. cout << testAlpha(5.0, "65", 2.0);
ANS: A PTS: 1 REF: 349-350

17. Given the function prototype:

float test(int, int, int);

which of the following statements is legal?


a. cout << test(7, test(14, 23));
b. cout << test(test(7, 14), 23);
c. cout << test(14, 23);
d. cout << test(7, 14, 23);
ANS: D PTS: 1 REF: 349-350

18. Which of the following function prototypes is valid?


a. int funcTest(int x, int y, float z){}
b. funcTest(int x, int y, float){};
c. int funcTest(int, int y, float z)
d. int funcTest(int, int, float);
ANS: D PTS: 1 REF: 349-350

19. Which of the following function prototypes is valid?


a. int funcExp(int x, float v);
b. funcExp(int x, float v){};
c. funcExp(void);
d. int funcExp(x);
ANS: A PTS: 1 REF: 349-350

20. Given the following function prototype: int myFunc(int, int);, which of the following
statements is valid? Assume that all variables are properly declared.
a. cin >> myFunc(y);
b. cout << myFunc(myFunc(7, 8), 15);
c. cin >> myFunc('2', '3');
d. cout << myFunc(myFunc(7), 15);
ANS: B PTS: 1 REF: 349-350

21. The statement: return 8, 10; returns the value ____.


a. 8 c. 18
b. 10 d. 80
ANS: B PTS: 1 REF: 351

22. The statement: return 37, y, 2 * 3; returns the value ____.


a. 2 c. y
b. 3 d. 6
ANS: D PTS: 1 REF: 351

23. The statement: return 2 * 3 + 1, 1 + 5; returns the value ____.


a. 2 c. 6
b. 3 d. 7
ANS: C PTS: 1 REF: 351

24. Given the following function:

int strange(int x, int y)


{
if (x > y)
return x + y;
else
return x – y;
}

what is the output of the following statement?

cout << strange(4, 5) << endl;

a. -1 c. 9
b. 1 d. 20
ANS: A PTS: 1 REF: 351

25. What value is returned by the following return statement?

int x = 5;
return x + 1;

a. 0 c. 6
b. 5 d. 7
ANS: C PTS: 1 REF: 351

COMPLETION

1. A(n) ____________________ parameter s a formal parameter that receives a copy of the content of
the corresponding actual parameter.

ANS: value

PTS: 1 REF: 365

2. When you attach & after the dataType in the formal parameter list of a function, the variable
following that dataType becomes a(n) ____________________ parameter.

ANS: reference

PTS: 1 REF: 365

3. A(n) ____________________ parameter is a formal parameter that receives the location (memory
address) of the corresponding actual parameter.

ANS: reference

PTS: 1 REF: 365

4. ____________________ parameters are useful in three situations:

• When the value of the actual parameter needs to be changed


• When you want to return more than one value from a function
• When passing the address would save memory space and time relative to copying a large amount of
data

ANS:
Reference
reference

PTS: 1 REF: 372

5. If a formal parameter is a nonconstant reference parameter, during a function call, its corresponding
actual parameter must be a(n) ____________________.

ANS: variable

PTS: 1 REF: 372

6. Stream variables (for example, ifstream and ofstream) should be passed by


____________________ to a function.
ANS: reference

PTS: 1 REF: 376

7. The ____________________ of an identifier refers to where in the program an identifier is accessible


(visible).

ANS: scope

PTS: 1 REF: 386

8. If a function needs to return more than one value, as a rule of good programming style, you should
change it to a(n) ____________________ function and use the appropriate reference parameters to
return the values.

ANS: void

PTS: 1 REF: 386

9. ____________________ identifiers are not accessible outside of the function (block).

ANS: Local

PTS: 1 REF: 386

10. In C++, :: is called the ____________________.

ANS: scope resolution operator

PTS: 1 REF: 390

11. A variable for which memory is allocated at block entry and deallocated at block exit is called a(n)
____________________ variable.

ANS: automatic

PTS: 1 REF: 395

12. A variable for which memory remains allocated as long as the program executes is called a(n)
____________________ variable.

ANS: static

PTS: 1 REF: 395

13. The program that tests a function is called a(n) ____________________ program.

ANS: driver

PTS: 1 REF: 396

14. A function ____________________ is a function that is not fully coded.


Test Bank for C++ Programming: From Problem Analysis to Program Design, 6th Edition – D.S.

ANS: stub

PTS: 1 REF: 398

15. The ____________________ of a function consists of the function name and its formal parameter list.

ANS: signature

PTS: 1 REF: 399

Visit TestBankBell.com to get complete for all chapters

You might also like