Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION 1 Given the function definition, which of the following are correct? int func(int n, double d) { int j = n; double sum =

QUESTION 1

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!

QUESTION 2

Which 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

QUESTION 3

Which 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(RAND_MAX)*5-2

D) rand()/static_cast (RAND_MAX)*2 +3

QUESTION 4

Here is a small program. Which of the statements about the variables is INcorrect?

#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) 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

QUESTION 5

Which 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

QUESTION 6

A 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

QUESTION 7

What 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.

QUESTION 8

Which 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

QUESTION 9

The 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

QUESTION 10

A 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

QUESTION 11

Which 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

QUESTION 12

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) 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

QUESTION 13

Where 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

QUESTION 14

In 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

QUESTION 15

What 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

QUESTION 16

Which 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

QUESTION 17

Given the array declaration, int a[20]; The first element is written as:

A) a[1]

B) a[0]

C) a[20]

D) a

QUESTION 18

Given 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

QUESTION 19

Are 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};

QUESTION 20

Which 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago