ITS-1390 Final Study Guide C++

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

The following contain several #include directives that may have problems. Which one has one or more problems?

#include "cctype "

Given the function, and the main function calling it: What is the output of the following code if you omit the ampersand (&) from the first parameter, but not from the second parameter? (You are to assume this code is embedded in a correct function that calls it.):#include <iostream> using namespace std; void func(int & x, int & y) {int t = x; x = y; y = t;} int main() {int u = 3; v = 4; // ... cout << u << " " << v << endl; func ( u, v ) cout << u << " " << v << endl; // ...}

3443

The value of the expression 20.0 * (9/5) + 32.0 is

52.0

The value of the expression 20.0 * (9.0/5) + 32.0 is

68.0

The person responsible for the initial development of C++ was

Barney Strousrdup

Before a variable in C++ is used, it must be

Defined

A break statement is used in loops only.

False

A computer program is a set of instructions intended for only the computer to follow.

False

C++ arrays check for out-of-range index values.

False

C++ uses only /* */ for comments.

False

Call-by-reference is restricted to void functions.

False

Comments have no value whatsoever and do not belong in a program.

False

If we execute the code fragment in an otherwise complete, correct program: n = 1; cout << n++ << " " << n++ << " " << n++ << endl; the output is guaranteed to be 1 2 3.

False

If we execute this code in an otherwise correct and complete program: n = 1; n = (n++) + (n++); the value of n is guaranteed to be 3 after the second line executes.

False

In C++ the variables Alpha, ALPHA and AlphA are the same identifier.

False

In C++ you can assign an expression of type double to a variable of type int with no problem.

False

In a sorting an array in decreasing order, the items in the array are rearranged so that for all j and k, if j < k, then array[j]<=array[k]

False

In the definition, double d[10] = {0.0}; only d[0] is initialized to zero, the rest are uninitialized, just like x in the definition double x;

False

In the sequential search algorithm, items are examined alternately, odd then evens, in order to find whether the target value is in the array (and if the target is present, to the index of the target.)

False

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.

False

One can use the & operator to extract the value that a pointer points to.

False

Pointer variables are just memory addresses and can be assigned to one another without regard to type.

False

Setting the width of output with the manipulator setw is different from setting the width with the width member function.

False

Suppose we have these declarations, int x = -1, y = 0, z = 1; This Boolean expression is correct and it does what the programmer intends. x < y < z

False

The names x,y, and z are satisfactory variable names for the lengths of the legs and hypotenuse of a triangle.

False

The namespace facility is a tool used that assists in the study of genealogy.

False

The programmer should never use a defined constant in an array declaration.

False

The range of values for an int variable is from about 0 to +2 billion.

False

The value of count is 0; limit is 10. Evaluate: (count != 0) | | (limit > 20)

False

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

False

To call a function with an array parameter, write the array argument as the array name followed by empty square brackets, as in f(a[], 7); (The first argument is an array a, the second is the size.)

False

To put a character into a cstring constant that causes the output to continue on the next line, insert the escape sequence \t into the string constant.

False

When a loop is nested in side another loop, a break or continue statement terminates or restarts the outermost loop of the nested loop structure.

False

With arrays, indices start at any number the programmer chooses to indicate in the definition.

False

In C++ the compiler will infer the type intended for a variable from the context in which the variable occurs.

Fasle

Indicate which of these remarks about function parameters and arguments is correct.

Formal parameters appear in a function call between parentheses following the function name.

Which of the following is not true of the || operator?

It can have one operand

If a class is named MyClass, what must the constructors be named?

MyClass

In C++ array indices, that is subscript values, must be

Non-negative

Which of the following are correct ways to end a loop using a test for end-of-file?

None of the above. You cannot control a loop using a test for end of file.

The following is false about the expression left || right.

The expression is false when left is false and right is true

What is the value of the bool valued expression, 1 < x < 10? Does the value of this depend on the value of x? Explain, and give the expression that the programmer probably meant.

This statement is incorrect and it is always true

Which of the following are restrictions on use of a stream variable (either ifstream or ofstream)

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

A C++ declaration introduces only an identifier's spelling and specifies its type.

True

A C++ declaration is a definition that also allocates storage for an identifier's value (or function's body etc.).

True

A call-by-value parameter may pass data only into a function

True

A sequence of calls to the library function rand ( ) generates mathematically incorrect random number sequences.

True

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.

True

C++ not only supports OOP but also supports other programming styles.

True

Consider the array declaration, int x[20];. There is no memory allocated for x[20].

True

Consider two blocks, one within another. C++ allows an identifier to be declared as a variable in each of these blocks.

True

Consider two blocks, one within another. If an identifier is declared as a variable in the inmost of theses two blocks, one cannot access this variable from the outer block.

True

Every programmer does not need to know all the details of what that programmer's team mates are doing in their projects to do the work assigned.

True

Extensive use of global variables is not a satisfactory replacement for the difficulties of parameter passing with functions.

True

Functions that call other functions van be tested independently of the called functions.

True

Given the declaration int x = 0; The follwing expression causes a divide by zero error: (x != 0) || (2/x < 1);

True

Given the two C++ array declarations: int a[10], b[10]; You cannot successfully compute one array, say a, then assign b to a: a = b;

True

If you need an array with more than one index, you can use a multidimensional array, which is actually an array of arrays.

True

In C++ Boolean values may be represented with the int values 0 for false and 100 for true.

True

In C++ you can assign an expression of type int to a variable of type double with no problem.

True

In a while loop, the Boolean_Expression is executed before each execution of the loop body.

True

Mixing call-by-reference and call-by-value parameters is acceptable.

True

OOP is an acronym that means Object Oriented Programming.

True

Setting the width of output with call to the width member function, affects only the next output.

True

The compiler has a problem distinguishing these two function definitions: void func(double &x){/*...*/} void func(double x){/*...*/}

True

The if, while and for statements control only one statement.

True

The value of count is 0; limit is 10. Evaluate: (count != 0)||(limit < 20)

True

The value of count is 0; limit is 10. Evaluate: (count == 0)&&(limit < 20)

True

The value of count is 0; limit is 10. Evaluate: count == 0 && limit < 20

True

There is a problem with the compiler distinguishing these two function definitions: void func(double x){/*...*/} double func(double x){/*...*/ return something_double;}

True

There should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new.

True

When using an array, it is not legal to access indexed variables with index values less than 0 or greater than or equal to the declared size of the array.

True

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

Ture

Which of the following is true concerning return statements that functions can have:

Value returning functions can have the statement return computed__values;

Which control construct repeats a sequence of statements zero or more times?

While statement, for statement

A file stream, fStr is open and attached to physical file.txt. To reset this file stream so that the file can be read again starting at the first line requires

With calling object fStr call close() then call open( ) with argument "fStr"

A switch statement must have

a break statement

Which of the following is true of the && operator?

a) It has two operands c) It uses short circuit evaluation d) It is the logical AND operator

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

a[0]

Given the array declaration, int a[20]; The last (legal) element is written as:

a[19]

A l-value is

assigned a value

Which of the following does the C++ language not support?

automatic garbage collection.

In C++, a variable that has been defined but not initialized may

be used in any way any identifier can be used.

An r-value is

can have a value fetched from it

The ____________ fstream member function closes a file stream. Explain why it is best to close a file when the program is through processing the data in the file.

close( )

Which of the following loop statements is guaranteed to iterate the body of the loop at least once?

do body while(control);

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;

gecko

The _______ member function takes a single char value from the input file, without regard to whether it is whitespace.

get

Which of the following is not true about the comma operator

has value equal to the value of the first expression in the list.

Suppose you have the following array declaration in a program. int yourArray[5]; Further suppose that in the implementation of C++ you are using an int that requires 4 bytes. i- When your program runs, how much memory is required for this array? ii- Suppose further that your array starts at memory location decimal 100. What will be the address of yourArray[3]? iii- If you wrote to the (illegal) index 7 position in yourArray to what address would this clobber?

i- The array takes 20 bytes, ii- yourArray[3] will be an int located at Address 112 iii- writing to yourArray[7] will clobber an int starting at location 128.

Which of the following control structures requires curly braces?

if-else

Which of the following is not correct for opening a file and attaching it to a file named File.txt? Assume proper file inclusion and proper using directives.

ifstream inStream; inStream.open("File.txt");

Are the following array initializations correct?

int x[4] = {8, 7, 6};

Which of the following is correct? When a function having an array formal parameter is called, the formal array parameter ...

is passed the address of the argument, and the function needs further information about the array size to safely use an array parameter

To determine whether a file was opened successfully, one can use the ___________ fstream member function

open( )

Which is not a C++ keyword.

totalWeight

To clear the show plus sign flag but leave the rest of the flags alone, you use the _____________ member function and argument.

unsetf(ios::showpos);

Which of the following function declarations with default arguments are correct?

void g(int length=1, int width, int height);

Which of the following overloadings will be invoked by this call? g (1, 2);

void g(int value, int count);

If a class is named MyClass, what must the destructor be named?

~MyClass


Set pelajaran terkait

Post Test: Extending to Three Dimensions

View Set

Texas Government (2306)- Political Parties- CH 6

View Set

Autism Spectrum Disorder (Part 1 )IRIS

View Set