COP1334 Final Exam

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

Which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

10

How many elements does the following array have? int bugs[1000];

1000

Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

15

What is the output of the following program? # include <iostream> using namespace std; void doSomething(int&); int main( ) { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int& num) { num = 0; cout << num << endl; }

2

What is the output of the following program? # include <iostream> using namespace std; void doSomething(int); int main( ) { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num) { num = 0; cout << num << endl; }

2

Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have?

3

What is the last legal subscript that can be used with the following array? int values[5];

4

What is the output of the following program? # include <iostream> using namespace std; void showDub(int); int main( ) { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; }

4

Which line in the following program contains the prototype for the showDub function? 1 # include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

4

What will the following code display? int numbers[ ] = {99, 87, 66, 55, 101 }; cout << numbers[3] << endl;

55

What is the output of the following program? # include <iostream> using namespace std; int getValue(int); int main( ) { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5; }

7

What will the following code display? int numbers[ ] = { 99, 87, 66, 55, 101 }; for (int i = 1; i < 4; i++) cout << numbers[i] << endl;

87 66 55

Which of the following statements about global variables is true?

A global variable can have the same name as a variable that is declared locally within a function.

A two-dimensional array of characters can contain:

A) strings of the same length B) uninitialized elements C) strings of different lengths D) All of these

In a function header, you must furnish:

A)names of parameter variables B) data type of the return value C) the name of function D) data type(s) of the parameters E) All of these

What will the following code do? const int SIZE = 5; double x[SIZE]; for(int i = 2; i <= SIZE; i++) { x[i] = 0.0; }

An error will occur when the code runs.

EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit( ) function is called.

EXIT_SUCCESS

A function's return data type must be the same as the function's parameter(s).

FALSE

A local variable and a global variable may not have the same name within the same program

FALSE

Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.

FALSE

An array initialization list must be placed on one single line.

FALSE

Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement. array1 = array2

FALSE

C++ limits the number of array dimensions to two.

FALSE

If you attempt to store data past an array's boundaries, it is guaranteed that the compiler will issue an error.

FALSE

Local variables are initialized to zero by default.

FALSE

The statement double money[25.00]; is a valid C++ array definition.

FALSE

When a function is called, flow of control moves to the function's prototype.

FALSE

You must furnish an argument with a function call.

FALSE

What does the following statement do? vector<int> v(10, 2);

It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.

What does the following statement do? vector<int> v(10);

It creates a vector object with a starting size of 10.

A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.

TRUE

A static variable that is defined within a function is initialized only once, the first time the function is called.

TRUE

An individual array element can be processed like any other type of C++ variable.

TRUE

Each individual element of an array can be accessed by the array name and an element number, called a subscript.

TRUE

Global variables are initialized to zero by default

TRUE

It is not considered good programming practice to declare all of your variables globally.

TRUE

It is possible for a function to have some parameters with default arguments and some without.

TRUE

One reason for using functions is to break programs into manageable units, or modules.

TRUE

The amount of memory used by an array depends upon the array's data type and the number of elements in the array.

TRUE

When you pass an array as an argument to a function, the function can modify the contents of the array.

TRUE

You may use the exit( ) function to terminate a program, regardless of which control mechanism is executing.

TRUE

________ functions may have the same name, as long as their parameter lists are different.

Two or more

To assign the contents of one array to another, you must use:

a loop to assign the elements of one array to the other array

When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list.

all but the first dimension

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function.

argument, parameter

Unlike regular variables, these can hold multiple values.

arrays

Subscript numbering in C++

begins with zero

Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function

call

A function is executed when it is:

called

Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function?

computeValue(10);

An array's size declarator must be a(n)________ with a value greater than ________.

constant integer expression, zero

A(n) ________ argument is passed to a parameter when the actual argument is left out of the function call.

default

These types of arguments are passed to parameters automatically if no argument is provided in the function call.

default

A function ________ contains the statements that make up the function

definition

It is a good programming practice to ________ your functions by writing comments that describe what they do.

document

Look at the following function prototype. int myFunction(double); What is the data type of the funtion's parameter variable?

double

The individual values contained in array are known as:

elements

This vector function returns true if the vector has no elements.

empty

This function causes a program to terminate, regardless of which function or control mechanism is executing.

exit( )

An array can easily be stepped through by using a:

for loop

This is a collection of statements that performs a specific task.

function

This is a statement that causes a function to execute.

function call

A ________ variable is declared outside all functions.

global

If a function does not have a prototype, default arguments may be specified in the function ________.

header

An array with no elements is:

illegal in C++

) The statement int grades[ ] = { 100, 90, 99, 80}; shows an example of:

implicit array sizing

A(n) ________ can be used to specify the starting values of an array.

initialization list

Arrays may be ________ at the time they are ________.

initialized, declared

) Look at the following function prototype. int myFunction(double); What is the data type of the funtion's return value?

int

Which of the following is a valid C++ array definition?

int array[10];

Which of the following is a valid C++ array definition?

int scores [10];

It is ________ to pass an argument to a function that contains an individual array element, such as numbers[3].

legal in C++

This type of variable is defined inside a function and is not accessible outside the function.

local

The name of an array stores the ________ of the first array element.

memory address

To pass an array as an argument to a function, pass the ________ of the array.

name

The ________ is automatically appended to a character array when it is initialized with a string constant.

null terminator

A two-dimensional array can have elements of ________ data type(s).

one

A function can have zero to many parameters, and it can return this many values.

only one

If a function is called more than once in a program, the values stored in the function's local variables do not ________ between function calls

persist

This vector function removes an item from a vector.

pop_back

A function ________ eliminates the need to place a function definition before all calls to the function

prototype

This vector function is used to insert an item into a vector.

push_back

When used as parameters, these types of variables allow a function to access the parameter's original argument.

reference

This statement causes a function to end.

return

A two-dimensional array can be viewed as ________ and ________.

rows, columns

Given the following declaration, where is 77 stored in the scores array? int scores[ ]={83, 62, 77, 97};

scores [2]

A two-dimensional array is like ________ put together.

several identical arrays

This vector function returns the number of elements in a vector.

size

The value in this type of local variable persists between function calls.

static

The value in a(n) ________ variable persists between function calls.

static local

An array of string objects that will hold 5 names would be declared using which statement?

string names[5];

This is a dummy function that is called instead of the actual function it represents.

stub

By using the same ________ you can build relationships between data stored in two or more arrays.

subscript

To access an array element, use the array name and the element's:

subscript

An element of a two-dimensional array is referred to by ________ followed by ________.

the row subscript of the element, the column subscript of the element

An array can store a group of values, but the values must be:

the same data type

Which statement correctly defines a vector object for holding integers?

vector<int> v;

If you leave out the size declarator in an array definition:

you must furnish an initialization list

Given the following function definition void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;

1 6 3

What will the following code display? int numbers[4] = { 99, 87 }; cout << numbers[3] << endl;

0


Set pelajaran terkait

2017 National Electrical Code Article 200 Use and Identification of Grounded Conductors.

View Set

*Chapter 6 Personal Finance Consumer Credit

View Set

Chapter 7: Inventory and Cost of Goods Sold

View Set

Maco/Micro Economics Chapter 1-4

View Set

Tennessee Health Insurance License Review ExamFX

View Set

Chapter 71: Care of Patients with Gynecologic Problems

View Set

Area and Perimeter of Triangles Assignment and Quiz

View Set