Chapter 3

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

C++ predefined functions... a) are usually provided in libraries b) make C++ harder than necessary c) don't usually require a header file d) are usually not provided with the C++ compiler

a) are usually provided in libraries

In the case of a void function the return statement ___________ any expression for a value returned and any return statement _________ . a) doesn't need, simply ends the function call b) handles, results in a value being sent back the next line after the last function call. c) automatically generates, simply ends the function call d) doesn't need, results in a value being sent back the next line after the last function call

a) doesn't need, simply ends the function call

fabs is the C++ abbreviation for ___________ . a) floating point absolute value b) floating point double value c) floating point integer value d) floating point long value

a) floating point absolute value

A return statement consists of a ________ followed by an _________ . a) keyword 'return', expression b) curly bracket, semicolon c) reserved word 'return', variable name d) set of parameters in parenthesis, semicolon

a) keyword 'return', expression

The primary difference between an argument and a parameter is that an argument is __________ . a) normally the value passed into the formal parameter upon the function call b) there isn't any real difference and the terms may be used interchangeably without worrying about confusing other people at all c) automatically applied to the correct formal parameter regardless of the positional logic d) assigned its position in the function definition and must be applied accordingly

a) normally the value passed into the formal parameter upon the function call

It is not true that a void function a) performs some action and returns a value b) performs some action but does not return a value c) is a statement d) call is written much like a call to a value returning function but is terminated with a semicolon e) A void function may have a return statement but is not required to have one

a) performs some action and returns a value

Given the following include directive (to get the declaration for the pow function from the math library): #include Now make these declarations: double base = 2,exponent = 3,power = 4; Which of the following is a correct invocation for the pow function? a) power = pow(base, exponent); b) pow(power, base, exponent); c) pow(base, exponent) = power; d) base = pow(exponent, power)

a) power = pow(base, exponent);

C++ functions are typically either _______ or _________ . a) predefined, programmer defined b) int, void c) defined, standard d) predefined, standard

a) predefined, programmer defined

Which of the following statements about the definition and declaration of functions is not correct? a) Function declaration is exactly the same as function prototype b) Function definition is exactly the same as function prototype c) A function header is exactly the same as function prototype except for the semicolon d) A function definition is a function header followed by the function block e) A function header syntax is the following: return_type function_name parenthesized_parameter_list

b) Function definition is exactly the same as function prototype

What does it mean when we say a programmer using a function should be able to treat the function like a black box? a) This is meaningless. One must know how a function does its job to effectively use it b) One must be able to rely on the description of the preconditions (requirements for use of the function) and the postconditions (promise of behavior to use the function) c) If one codes an application that uses a function with a knowledge of the internal mechanism of that function, then when the function's maintainer changes its internal mechanism, the application programmer could be faced with changing the application code extensively d) The most efficient programs are the ones that each function is designed to maximally use the internal behavior of every other function to speed up the code

b) One must be able to rely on the description of the preconditions (requirements for use of the function) and the postconditions (promise of behavior to use the function)

A void function can have a) no arguments b) as many arguments as there parameters c) no more than 3 arguments d) exactly one argument

b) as many arguments as there parameters

In c++ there are three abs (absolute value) functions. If you want to produce a value of type long you should use labs, if you want to produce a value of type int use abs, and if you want to produce a value of type double use _______ . a) dabs b) fabs c) tabs d) ddabs

b) fabs

A definition of a variable outside any function is called a a) local function definition b) global variable definition c) global function header d) global function definition e) local variable definition

b) global variable definition

A function definition consists of a function ______ followed by a function _____. a) declaration, parameters b) header, body c) prototype, declaration d) identifiers, formal parameters

b) header, body

A global named constant _________________ . a) is declared at the beginning of the program and inside of the main function b) is declared at the beginning of the program and outside the body of any function. c) is declared just before it is used as an argument in a function call d) can be easily changed within any function and the changed value is simply returned out of the function into the global constant

b) is declared at the beginning of the program and outside the body of any function.

The main function in your program ____________ . a) doesn't need a return and if it does it doesn't have to be anything specific b) needs a return for the sake of portability and should always be of type int c) should always be called using 'main()' d) should always be called using 'main();'

b) needs a return for the sake of portability and should always be of type int

What do the calls to exit(...) do when exit(0) and exit(1) are called? a) The exit( ) function stops the program. The argument is discarded b) The exit( ) function is obsolete. There is no longer any such function in the C++ libraries c) The exit( ) function stops the program. The argument is passed to the operating system which uses it for an error code d) The exit( ) function temporarily stops the program, and sends the argument to the operating system which uses it for an error code. The operating system restarts the program after fixing the error e) The exit( ) function allows the systems programmer to escape when the power supply catches fire

c) The exit( ) function stops the program. The argument is passed to the operating system which uses it for an error code

What is the difference between executing the return 0; statement and its rough equivalent, a call to the exit(0); function, or the difference between return 1; and exit(1);? a) These are very nearly equivalent anywhere they are encountered b) These are the same if encountered in a function other than main();.The exit function terminates the program, returning control to the operating system, whereas return only terminates the function, returning control to the calling function c) These are very nearly equivalent when executed in the main function. In main, these both terminate main and send a success code to the operating system, returning control to the operating system d) Both these return control to the free store manager by way of the exception controller, sending the argument as an error code

c) These are very nearly equivalent when executed in the main function. In main, these both terminate main and send a success code to the operating system, returning control to the operating system

Where can you not declare a variable in a C++ program? a) Within the parameter list of a function definition b) Within the block of a void function. c) Within the argument list of a function call d) Within a block nested within another block e) Within the block of a value returning function

c) Within the argument list of a function call

A semicolon (usually) goes after which of these? a) while(condition) b) if(condition) c) a function header to make it a function declaration d) int main( )

c) a function header to make it a function declaration

One way to write a good function declaration comment is to break it down into a precondition and a postcondition. The precondition ________, and the postcondition __________ . a) sets the initial conditions as boolean true or false, describes the effect of the function call b) clearly states what is assumed to be true when the function is called, states what the ending condition will be as either boolean true or false c) clearly states what is assumed to be true when the function is called, describes the effect of the function call d) sets the initial conditions as boolean true or false, states what the ending condition will be as either boolean true or false

c) clearly states what is assumed to be true when the function is called, describes the effect of the function call

If your program uses a predefined function from some library, then it must contain an ________ statement that names that ________ . a) include pointer, library b) include pointer, function name c) include directive, library d) include directive, function name

c) include directive, library

Which of the following are not names of a C++ library function: a) abs b) sqrt c) random d) floor e) labs

c) random

A void function performs some action but does not _________ and is _________ . a) return a value, not a statement b) require an include statement, not a statement c) return a value, terminated with a semicolon d) require an include statement, terminated with a semicolon

c) return a value, terminated with a semicolon

Which of the following code fragments gives a random double value between 2 and 5 inclusive? You can assume that the random number seed has been set and any needed definitions and initializations have been made. a) 3.0*rand() + 2 b) 3.0*(RAND_MAX-rand())/RAND_MAX + 2 c) ((RAND_MAX-rand())/static_cast(RAND_MAX))*3 + 2 d) (RAND_MAX-rand())/static_cast(RAND_MAX)*5 -2 e) rand()/static_cast(RAND_MAX)*2 + 3

d) (RAND_MAX-rand())/static_cast(RAND_MAX)*5 -2

A call to a C++ function is a) The name of the function followed by empty parentheses. b) The name of the function followed by any number of arguments, regardless of the number of parameters in the definition c) The name of the function followed by a number of arguments not greater than the number of parameters in the definition d) The name of the function followed by exactly the number of arguments as there are parameters in the definition e) The name of the function only

d) The name of the function followed by exactly the number of arguments as there are parameters in the definition

Assume this code fragment is embedded in an otherwise correct and complete program. What should be the output from this code segment? { for( int i = 0; i < 10;i++) } . . . { cout << i << endl; } a) 10 b) 9 c) 0 d) The variable i is undefined in this scope, so this should not compile

d) The variable i is undefined in this scope, so this should not compile

When your program is run the main function is __________ . a) not called unless it is needed b) called by the statement 'main()' c) called by the statement 'main();' d) automatically called and may call other functions

d) automatically called and may call other functions

Here is a small program. Which of the statements about the variables is correct? #include const double NUM = 2.9345358; double num = 3; double numTimes(int x); int main( ) {using namespace std; int value; cout << "Enter a value, I'll multiply it by " << NUM << endl; cin >> value; cout << "You entered " << value << " NUM times this is " << numTimes(value) << endl; return 0;} double numTimes(int x){double d; d = NUM * x; return d;} a) NUM is a local constant variable b) num is a global constant c) value is local variable in the main function d) d is a local variable in the numTimes function

d) d is a local variable in the numTimes function

A __________ describes how the function computes the value it returns. a) function declaration b) function body c) function header d) function definition

d) function definition

Usually all you need to do to use a library is to place an _______ directive and a _______ directive for that library in the file with your program. a) include, namespace b) using, namespace c) standard, namespace d) include, using

d) include, using

The variables used in any particular function are called ________ . a) global variables b) declared variables c) parameter arguments d) local variables

d) local variables

The primary difference between a function declaration and a function definition is that ___________ . a) the function declaration does not require a semicolon at the end of the statement b) the function definition goes at the beginning of the program before the int main{} function c) there isn't any big difference between the two because they are the same thing d) the function definition must always have the formal parameter names

d) the function definition must always have the formal parameter names

Concerning return statements that functions can have: a) Value returning functions can have the statement: return (any computed_value); b) void functions can have the statement: return void; c) void functions must have a return; statement, with no argument. d) void functions may terminate using a return; statement without an argument, or they may have no return statement at all, terminating by falling off the end of the function block.

d) void functions may terminate using a return; statement without an argument, or they may have no return statement at all, terminating by falling off the end of the function block.

It is not true that a C++ predefined function a) argument is the value the predefined function starts with b) may be called any number of times in a program. c) computed value is the return value d) call is an expression that has the type specified as the return type of the function and can be used anywhere any other expression of that type could be used. e) #include is all that is ever necessary to provide access.

e) #include is all that is ever necessary to provide access.

Given the function definition, with arguments 7and 2.0 when the function was called, which of the following are correct? int func(int n, double d) {int j = n; double sum = 0; while( j >= 0) {sum += d; --j; } return sum;} a) returns 7*2 b) returns 7+2 c) returns 7! d) There is a syntax error in the program so it won't run. e) It compiles but computes none of these.

e) It compiles but computes none of these.

The sqrt function... a) is provided in the library header b) returns the square of the argument c) returns the nth root of the argument d) the argument type is int e) the return type is double.

e) the return type is double.


संबंधित स्टडी सेट्स

Ch. 7 Portable Fire Extinguishers

View Set

Colin Beggs Bio 1st semester exam review

View Set

PrepU Chapter 6: Values, Ethics, and Advocacy

View Set

Ch 12: Organization, Stock transactions, and Dividends

View Set

Chapter 17: Science, the Enviornment, and Society

View Set

21 বাংলাদেশের আবহাওয়া থেকে ডাক-ব্যবস্থা

View Set

Spanish III: Cultura Estados Unidos

View Set