The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 327 Weeks Ago, 5 Days Ago |
| Questions Answered: | 12843 |
| Tutorials Posted: | 12834 |
MBA, Ph.D in Management
Harvard university
Feb-1997 - Aug-2003
Professor
Strayer University
Jan-2007 - Present
True False:
An explanation is required.
1. Procedural abstraction involves information hiding in that only the 'contract' between the programmer using the function (the client) and author of a function is known to either.
2. Code after a return or a call to the exit function is executed will not be executed.
3. A sequence of calls to the library function rand() generates mathematically correct random number sequences.
4. It is legal to replace the prototype
double totalCost(int numberParam, double priceParam);
with the more terse, alternate form
double totalCost(int, double);
5. In C++ Boolean value are represented only with the int values 0 for false and 1 for true.
6. Extensive use of global variables is a satisfactory replacement for the difficulties of parameter passing with functions.
7. A variable declared outside any function is said to be a local variable.
8. A variable declared within a function block is said to be local to the function.
9. Consider two blocks, one within another. C++ prohibits an identifier to be declared as a variable in each of these blocks.
10. Calling something a black box is a figure of speech that conveys the idea that you cannot see inside. You know its behavior and interface but not its implementation.
1. The sqrt function
a) is provided in the library header.
b) returns the square of the argument
c) returns the square root of the argument
d) the argument type is int
e) the return type is double.
2. 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.
3. What do the calls to exit(…) do? When exit(0) and exit(1) are called, what receives these arguments and what is done with them?
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.
4. A void function can have
a) no arguments
Test Bank for Savitch Absolute C++ 5e Page 3
3
b) as many arguments as the programmer wishes
c) no more than 3 arguments
d) exactly one argument
5. 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
6. Concerning return statements that functions can have:
a) Value returning functions can have the statement return 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.
7. 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.
8. Given the function definition, which of the following are correct?
int func(int n, double d)
{
int j = n;
double sum = 0;
while( j >= 0)
{
Test Bank for Savitch Absolute C++ 5e Page 4
4
sum += d;
--j;
}
return sum;
}
With arguments 6 and 8.0
a) returns 6*8
b) returns 6+8
c) returns 7*8
d) returns 7 + 8
e) There is a syntax error in the program so it won’t run.
9. Suppose the function from Display 3.7 has the return statement removed. Which of the statements below regarding this change are correct? Why?
void iceCream(int number, double totalWeight)
{
if(number == 0)
{
cout return;
}
portion = totalWeight/number;
cout a) The code will not compile.
b) The code will compile and run. The output will be unchanged.
c) The code will compile. For a zero number of customers the code would produce a divide by zero run-time error.
Test Bank for Savitch Absolute C++ 5e Page 5
5
d) The program will compile and run correctly for 1 or more customers. The error for zero number of customers could be repaired by placing an else after the block belonging to the if.
10. 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 cin >> value;
cout return 0;
}
double numTimes(int x)
{
double d;
d = NUM * x;
return d;
}
a) NUM is a global 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.