Programming Final

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

What will the following code display? #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 0 2

How many times will the following loop display "Hello world!"? for (int i = 0; i < 20; i++) cout << "Hello world!" << endl;

20

How many times will the following loop display "Looping!"? for (int i = 20; i > 0; i--) cout << "Looping!" << endl;

20

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

4

What will the following code display? #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 2

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

55

What will the following code display? int number = 6; cout << number++ << endl;

6

What will the following code display? int number = 6; int x = 0; x = number--; cout << x << endl;

6

What will the following code display? int number = 6; number++; cout << number << endl;

7

What will the following code display? int x = 0; while (x < 5) { cout << x << " "; x++; }

01234

What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++;

1 1 ... and on forever

Given the following function: 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 segment that invokes calc(): int x = 1; int y = 2; int z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;

1 6 3

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

11

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

Two or more

The following statement shows an example of ___________. int grades[] = {100, 90, 99, 80};

implicit array sizing

An array can easily be stepped through by using

for loop

A collection of statements that performs a specific task is a(n)

function

A _________ variable is declared outside all functions.

global

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

header

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

When the increment operator precedes its operand, as ++num, the expression is in __________ mode.

prefix

The range-based for loop in C++11 is designed to work with a built-in variable known as

range variable

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

reference

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

static

An array of string objects that will hold five names would be declared with which of the following statements?

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

the row subscript of the element followed by the column subscript of the element

A for statement contains three expressions: initialization, test, and

update

You may define a __________ in the initialization expression of a for loop.

variable

C++ limits the number of array dimensions to two. (T/F)

False

If you attempt to store data past an array's boundaries, it is guaranteed to cause a compiler error. (T/F)

False

Local variables are initialized to zero by default. (T/F)

False

The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon. (T/F)

False

The increment and decrement operators can be used in mathematical expressions; however, they cannot be used in relational expressions. (T/F)

False

The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop. (T/F)

False

When a function is called, flow of control moves to the function's prototype. (T/F)

False

You may nest while and do-while loops but you may not nest for loops. (T/F)

False

You must always furnish an argument with a function call. (T/F)

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.

If an array is partially initialized, the uninitialized elements will be set to zero. (T/F)

True

If you want to stop a loop before it goes through all of its iterations, the break statement may be used. (T/F)

True

In C++11 the range-based for loop is best used in situations where you need the element subscript for some purpose. (T/F)

True

It is possible for a function to have some parameters with default arguments and some without. (T/F)

True

One reason for using functions is to break programs into manageable units or module. (T/F)

True

The amount of memory used by an array depends on the array's data type and the number of elements in the array. (T/F)

True

The update expression of a for loop can contain more than one statement, for example: for(i = 5; i <= 10; i++, total+= sales) (T/F)

True

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

0

To allow file access in a program, you must use __________ in the header file.

#includefstream

These are operators that add and subtract one from their operands.

++and--

An array initialization must be all on one line. (T/F)

False

A function's return data type must be the same as the function's parameters. (T/F)

False

A local variable and a global variable may not have the same name within a program. (T/F)

False

A while loop is somewhat limited because the counter can only be incremented by one each time through the loop . (T/F)

False

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

False

A parameter is a special purpose variable that is declared inside the parentheses of a function definition. (T/F)

True

A static variable that is defined within a function is initialized only once, the first time it is called. (T/F)

True

A vector object automatically expands in size to accommodate the items stored in it. (T/F)

True

A while loop's body can contain multiple statements, as long as they are enclosed in braces. (T/F)

True

An individual array element can be processed like any other type of C++ variable. (T/F)

True

An initialization expression may be omitted from the for loop if no initialization is required. (T/F)

True

An output file is a file that data is written to . (T/F)

True

Each individual element of an array can be accessed by the array name and the element subscript. (T/F)

True

Global variables are initialized to zero by default. (T/F)

True

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, __________ can hold multiple values.

arrays

The statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed

at least once

Subscript numbering in C++

begins with zero

A statement that causes a loop to terminate early is

break

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

call

A function is executed when it is

called

Given the following header for a function named computeValue, which of the following is a valid call to the function? void computeValue(int value)

computeValue(10);

A variable that is regularly incremented or decremented each time a loop iterates is a

counter

A function __________ contains the statements that make up the function.

definition

The __________ loop is ideal in situations where you want the loop to iterate at least once.

do-while

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

document

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

exit()

Something within a while loop must eventually cause the condition to become false or a(n) __________ results.

infinite loop

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

int

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 scores[3].

legal in C++

This is a control structure that causes a statement or group of statements to repeat.

loop

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

name

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

one

A file must be __________ before data can be written to or read from it.

opened

Which statement correctly defines a vector object for holding integers?

vector<int> v;

The __________ loop is a good choice when you do not want the loop to iterate if the condition is false in the beginning.

while

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

you must furnish an initialization list


Set pelajaran terkait

Module 47: Introduction to Psychological Disorders

View Set

Global Environment of Business Test 1

View Set

AP Chapter 16: Changing Balance of World Power

View Set

International MKT Chapter 3, International Marketing Exam 1, international ch 1, International Marketing model 1, intl mktg chapter 4, Global Marketing Exam 1 Review, Global Marketing Exam 1, Global Marketing exam 1, Global Marketing Exam #1 (Chapter...

View Set

US Government: 1.06 Unit Test: Lessons 2-5 Part 1

View Set