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: | Jul 2017 |
| Last Sign in: | 313 Weeks Ago, 5 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
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)
{
sum += d;
-j;
}
return sum;
}
A) returns 7+2
B) It compiles but computes none of these
C) returns 7*2
D) returns 7!
10 points Â
QUESTION 2Which of the following statements about the definition and declaration of functions is incorrect?
(Note. Function definition includes the body of the function also called function block)
A) Function definition is exactly the same as function prototype
B) Function declaration 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
10 points Â
QUESTION 3Which of the following code fragments gives a random 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<double>(RAND_MAX)*5-2
D) rand()/static_cast (RAND_MAX)*2 +3
10 points Â
QUESTION 4Here is a small program. Which of the statements about the variables is INcorrect?
#include <iostream>
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) the line
doublenumTimes(int x); is a function definition
B) The variable x is a parameter in function numTimes
C) the variable value is an argument in a call to numTimes
D) The line return d; in the function numTimes is necessary
10 points Â
QUESTION 5Which is incorrect?
C++Â predefined functions
A) make C++Â harder than necessary
B) must use #include for the proper header file
C) are usually provided in libraries
D) are usually provided with the C++Â compiler
10 points Â
QUESTION 6A semicolon does not (usually)Â go after these with the exception of
A) if (condition)
B) int main()
C) while (condition)
D) a function header to make it a function declaration
10 points Â
QUESTION 7What do the calls to exit(...) do? When exit(0) and exit(1) are called, what receives these values and what is done with them?
A) the exit() function stops the program. The value is passed to the operating system which uses it for an error code
B) the exit() function is obsolete. There is no longer any such function in the C++ libraries
C) 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.
D) the exit() function stops the program. The value is discarded.
10 points Â
QUESTION 8Which statement is incorrect?
A) In C++Â Boolean value are represented only with the int values 0Â for false and 1Â for true
B) A variable declared outside any function is said to be a global variable
C) It is legal to replace the prototype
double totalCost(int numberParam, double priceParam);
with the more terse, alternate form
double totalCost(int, double);
D) Extensive use of global variables is NOT a satisfactory replacement for the difficulties of parameter passing with functions
10 points Â
QUESTION 9The definition of a variable outside any function is called
A) local variable definition
B) global function header
C) global variable definition
D) global function definition
10 points Â
QUESTION 10A void function can have
A) no arguments
B) as many arguments as the programmer wishes
C) exactly one argument
D) no more than 3Â arguments
10 points Â
QUESTION 11Which statement is incorrect?
A) Consider two blocks, one within another. C++ allows an identifier to be declared as a variable in each of these blocks
B) A variable declared within a function block is said to be local to the function
C) Consider two blocks, one within another. If an identifier is declared as a variable in the innermost of these two blocks, one can access this variable from the outer block
D) A local variable is created in the execution stack
10 points Â
QUESTION 12Here is a small program. Which of the statements about the variables is correct?
#include <iostream>
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) d is a local variable in the main function
B) value is a local variable in the main function
C) num is a global constant
D) NUM is a global variable
10 points Â
QUESTION 13Where can you NOT declare a variable in a C++Â program?
A) Within a block nested within another block
B) Within the argument list of a function call
C) Within the block of a void function
D) Within the parameter list of a function definition
10 points Â
QUESTION 14In C++ array indices, that is subscript values, must be
A) Less than or equal to the declared size of the array
B) positive
C) Non-negative, integery
D) None is correct
10 points Â
QUESTION 15What is the output of the following code (assuming it is embedded in a correct and complete program)?
Â
char letter[5] = {'o', 'k', 'c', 'e', 'g'};
for(int i = 4; i >= 0; i-- )
cout << letter[i];
cout << endl;
Â
A) kceg followed by a character from an out of bounds access
B) gecko
C) okceg
D) ecko followed by a character from an out of bounds access
10 points Â
QUESTION 16Which statement is incorrect?
A) Indexed variables for an array are stored wherever the computer finds memory for the first indexed variable, then the next one is stored next to the first if there is space, and someplace else if not.
B) If you need an array with more than one index, you can use a multidimensional array, which is actually an array of arrays
C) C++ arrays do not check for out-of-range index values
D) A for-loop is a convenient way to step through an array
10 points Â
QUESTION 17Given the array declaration, int a[20]; The first element is written as:
Â
A) a[1]
B) a[0]
C) a[20]
D) a
10 points Â
QUESTION 18Given the definition and code fragment:
int matrix[2][3];
int k = 0;
for(int i =0; i < 3; i++)
for (int j=0, j < 4; j++)
matrix[i][j] = k++;
The value of matrix[0][0] is
Â
A) 0
B) 1
C) 2
D) 3
10 points Â
QUESTION 19Are the following array initializations INcorrect?
A) const int SIZE =4;
int x[SIZE];
Â
B) int x[4] = {8, 7, 6, 5, 4};
Â
C) int x[4] = {8, 7, 6};
Â
D) int x[] = {8, 7, 6, 5, 4};
Â
10 points Â
QUESTION 20Which statement is incorrect?
A) With arrays, indices start with the number 0
B) If we want to find the median of 100 scores, we need 100 separate variables to hold the data
C) An array behaves like a list of variables each of which is of the same type and for which there is a uniform, convenient naming convention that can be declared in a single line of code.
D) The programmer should always use a defined constant in an array declaration
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly