These test questions are true-false, fill in the blank, multiple choice, and free form questions that may require code. The multiple choice questions may have more than one correct answer. You are required to mark and comment on correct answers.. Mark all of the correct answers for full credit. The true false questions require an explanation in
addition to the true/false response, and, if false, also require a correction.
True False:
An explanation is required.
- Every programmer must know all the details of what that programmer’s team mates are doing in their projects to do the work assigned. Why?
Answer:. False
Explanation: Only the client programmer needs to know the use to which a function is put. Only the author of the function needs to know the internals. The only thing these two share is the contract or specification of the function.
- 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.
Answer: True.
Explanation: Under procedural abstraction, the author (or programmer) of a given function should know about how the application programmer (or the client) will use the function is IN the ‘contract.’ The contract is what the function is to do, and the conditions set on the parameters to guarantee that the function can do IT. The author should not need not know how the function is to be used by the client programmer. The client programmer should know only only needs to know what the function does, the requirements on the parameters, but not how the function carries out the task. This way each can do his job independently of the other.
- Code after a return or a call to the exit function is executed will not be executed.
Answer: True. Control returns to the caller if return is executed out of a called function, and returns to the operating system if return is executed out of main. If exit is executed anywhere, the program is terminated and control is returned to the operating system.
- A sequence of calls to the library function rand() generates mathematically correct random number sequences.
Answer: False.
Explanation: The sequence is called pseudorandom because it appears to be random. The results are good enough to obtain usable answers with computer simulation.
- It is legal to replace the prototype
double totalCost(int numberParam, double priceParam);
with the more terse, alternate form
double totalCost(int, double);
Answer: True.
Explanation: The alternate form applies only to function declarations. You will see this form in manuals. It is possible to omit variable names that will not be used in function definitions, but the text does not do this.
- In C++ Boolean value are represented only with the int values 0 for false and 1 for true.
Answer: False.
Explanation: In C++ the bool type is a real type, with values true and false, but 0 is interpreted as true and 0 as false, and true and false will be converted to 1 and 0 respectively.
- Extensive use of global variables is a satisfactory replacement for the difficulties of parameter passing with functions.
Answer: False.
Explanation: Global variable use ties functions together so tightly that it is impossible to understand any one function’s behavior apart from the whole of the program. This complexity makes understanding a program very difficult.
- A variable declared outside any function is said to be a local variable.
Answer: False.
Explanation: This is a global variable.
- A variable declared within a function block is said to be local to the function.
Answer: True
Explanation: Such a variable is said to be local to the function or to have the function as its scope, and is also known as a local variable if the scope is clear from the context.
- Consider two blocks, one within another. If an identifier is declared as a variable in the inmost of these two blocks, one can access this variable from the outer block.
Answer: False:
Explanation: The scope of a local variable extends from the definition to the end of the block in which the variable is defined. This excludes the outer block.
- Consider two blocks, one within another. C++ prohibits an identifier to be declared as a variable in each of these blocks.
Answer: False
Explanation: Without the inner variable, the scope of the outer variable would be the entire outer block, including the inner block. The variable with the inner block for its scope shadows the outer variable’s scope, making a hole in the scope of the outer variable.
Contact us to get the test bank
0
835