Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.Which is correct? A)The compiler ha no problem distinguishing these two function definitions: void func(double &x){/*...*/} void func(double x){/*...*/} B)There is no problem with the

1.Which is correct?

A)The compiler ha no problem distinguishing these two function definitions:

void func(double &x){/*...*/}

void func(double x){/*...*/}

B)There is no problem with the compiler distinguishing these two function definitions:

void func(double x){/*...*/}

int func(double x){/*...*/ return something_double;}

C)Names of parameters in functions, especially function prototypes, have no meaning, and may be selected quite arbitrarily.

D)Call-by-reference is restricted to void functions

2.Which is correct?

A)There is only one kind of parameter passing in C++, namely call-by-value

B) The call-by-reference mechanism is specified in the function declaration and definition, using a $ between the type and the parameter

C) The position of the ampersand in the function header is of no importance to the proper compiling and execution of code that uses call-by-reference parameters

D) A call-by-reference parameter may pass data only out of a function

3.Consider the function, where the programmer inadvertently left out the ampersand in the definition of parRef. What is the output of the code?

void doStuff(int parValue, int parRef)

{

parValue = 100;

cout << "parValue in call to doStuff = "

<< parValue << endl;

parRef =222;

cout << "parRef in call to doStuff = "

<< parRef << endl;

}

and consider the call, which we assume is in a complete and correct program

int n1 = 1, n2 =2;

doStuff(n1, n2);

cout << "n1 after call to doStuff = " << n1 << endl;

cout << "n2 after call to doStuff = " << n2 << endl;

A) x parValue in the call to doStuff = 100;

parValue in the call to doStuff = 222;

n1 after function call = 100

n2 after function call = 2

B) parValue in the call to doStuff = 100;

parValue in the call to doStuff = 222;

n1 after function call = 1;

n2 after function call = 2

C) parValue in the call to doStuff = 100;

parValue in the call to doStuff = 222;

n1 after function call = 1;

n2 after function call = 222

D) parValue in the call to doStuff = 100;

parValue in the call to doStuff = 222;

n1 after function call = 100

n2 after function call = 222

4.Which of the following is a restriction on use of a stream variable (either ifstream or ofstream)?

A)To use a stream variable as a function parameter you can only use call-by-reference

B)A file variable can be used in any way any other variable can be use

C)To use a stream variable as a function parameter you can only use call-by-value

D)To use a stream variable as a function parameter you can use call-by-value or call-by-value

5.Which of the following is a restriction on use of a stream variable (either ifstream or ofstream)?

A)To use a stream variable as a function parameter you can only use call-by-reference

B)A file variable can be used in any way any other variable can be use

C)To use a stream variable as a function parameter you can only use call-by-value

D)To use a stream variable as a function parameter you can use call-by-value or call-by-value

6.

Which statement is incorrect?

A) Linear search data in the set can be unsorted, Binary search data in the set must be sorted

B)Linear search uses less comparisons than Binary search if the target is at the beginning of the set

C) Binary search uses less comparisons than Linear search if the target is exactly in the middle of the set

D)Linear search uses more comparisons than Binary search if the target is at the end of the set

7.Which statement is incorrect?

A)The statement

vector partnums[ 4];

creates a vector of initial size 4;

B)The statement

partnums[3] = 144;

works regardless of whether partnums is an array or a vector

C)The statement

int partnums[]={136, 122, 109, 146};

creates an array of size 4

D)The statement

cout << partnums.size() << endl;

works only if partnums is a vector

8.Which statement is incorrect?

A)An array cannot be resized

B) An array can be used to create a vector

C)An array can be resized to hold more elements but not less

D)A vector resizes automatically

9.Which statement is incorrect?

A)When you write

ifstream inStream;

inStream.open("infile.dat");

the file infile.dat must be located in the directory where the program is being run

B)When you use the open member function to tie a file name to a file stream, the file name is called the external file name, the program refers to the file by the stream variable used to open the file

C)The flush function copies the file buffer to the file on the file medium (disk, etc)

D)A file is automatically closed when a program terminates, so there is never a need to close a file

10.Which statement is incorrect?

A)When program calls the setf function on an output stream, the effect continues until the program calls unsetf with the same argument to turn it off

B)The manipulators endl and function setf() and precision are provided by the iostream header. The manipulators setw and setprecision are provided by the iomanip header.

C)Setting the width of output with call do the width() function, affects only the next output

C)Setting the width of the output with the manipulator setw has a different result from setting the width with the width function

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