exam 2 questions

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

To allow file access in a program, you must include this header file.

#include fstream

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

0 1 2 3 4

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

1 1 1 ... and on forever

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? x = 1; y = 2; z = 3; calc(x,y); cout << x << " " << y << " " << z << endl;

1 6 3

how many elements does the following array have? int values[1000]

1000

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 0

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

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

20

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

21

in the following prototype, how many parameter variables does this function have? int myFunction (double, double, double)

3

what will the following code display? int x = 0; for (int count = 0, count < 3, count++) x += count cout << x << endl;

3

Which line in the following program contains the prototype for the showDub function?

3: void showDub(int);

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

4

what will the following code display? 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 number = 6; Int x = 0; X = number--; Cout << x << endl;

5

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 cout << ++number << endl;

7

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

87 66 55

in the following expression, which operator is used first? while (x++ < 10)

<

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

EXIT_SUCESS

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-dimentional arrays as arguments, ___ must be stated in the parameter list.

all EXCEPT THE FIRST

a two-dimensional array can contain

all of these

a ___ is information passed to a function, and a ___ is information that is received by a function

argument, parameter

Unlike regular variables, these can hold multiple values.

arrays

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

at least once

subscript numbering in C++

begins with zero

statement that causes loop to terminate early

break

a function is executed when it is

called

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

constant, zero

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

counter

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

The individual values contained in array are known as ________.

elements

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

error will occur

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

the ___ loop is a good choice for when you know how many times you want the loop to iterate in advance.

for loop

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

function header

a ___ variable is declared outside all functions

global

An array with no elements is ________.

illegal in C++

the following statement shows an example of ___ int grades [ ] = {100, 90, 99, 80}

implicit array sizing

in a for statment, this expression is executed only once.

initialization

a ___ can be used to specify the starting values of an array

initialization list

Arrays must be __________ at the time they are __________.

initialized, declared

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

int scores [25];

which of the following is a valid array definition?

int sizes [10];

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

legal in C++

which line contains the header for the showDub function?

line 11 void showDub (int num)

which line in the program contains a call to the showDub function?

line 7 showDub(x)

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

local

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

name

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n):

null statement

the ___ is automatically appended to a character array when it is initialized with a string constant

null terminator

to write data from a file, you define an object of this data type.

ofStream

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

only one

a two-dimensional array can have elements of ___ data type(s)

only one data type

To read data from a file, you define an object of this data type.

outFile/ifStream

the while loop is a ___ loop

pretest

a function ___ eliminates the need to place a function definition before all calls to the function

prototype

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

range variable

When used as parameters, ______ variables allow a function to access the parameters original argument.

reference

this statement causes a function to end

return

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

scores[2]

a special value that marks the end of a list of values is a

sentinel

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

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

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

the same data type

the two important parts of a while loop is: 1. the expression that is tested for true or false and 2. ?

the statement or block that is repeated as long as the expression is true

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

two or more

a for statement contains 3 expressions: initialization, test, and ___

update

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

you must furnish an initialization list


Set pelajaran terkait

Verifying Trigonometric Identities

View Set

INT MKT Ch 4 Cultural Dynamics in Assessing Global Markets

View Set

Chapter 7 - Social and Emotional Development in Infants and Toddlers

View Set

AP US Government and Politics Midterm

View Set