CS 1336 Final Exam

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

++ and --

Which of the choices of code segments executes and produces the same result as the following code segment ? bool aBool, bBool; If ( aBool ) If ( bBool ) cout << "Here I am" << endl;

// if ( aBool && bBool ) cout << "Here I am" << endl;

After the following statements execute, what are the contents of matrix ? int j, k; for (j = 0; j < 3; j++) for (k = 0; k < 2; k++) matrix[j][k] = j + k;

0 1 1 2 2 3

Assume you have the following declaration char nameList[100]; Which of the following ranges is valid for the index of the array nameList ?

0 through 99

Assume you have the following declaration double salesData[1000]; Which of the following ranges is valid for the index of the array salesData ?

0 through 999

What is the output of the following C++ code? int alpha[5] = {2, 4, 6, 8, 10}; int j; for (j = 4; j >= 0; j--) cout << alpha[j] << " ";

10 8 6 4

The following statement displays: cout << 1 % 4;

2

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

20

What does the following code segment display? bool aBool = false, bBool=true; if (aBool) if (bBool) cout << "2"; else cout <<"3"; cout <<"4"

4

What is the value of alpha[2] after the following code executes? int alpha[5]; int j; for (j = 0; j < 5; j++) alpha[j] = 2 * j + 1;

5

What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 1; j < 5; j++) cout << list[j] << " ";

5 10 15 20

Consider the following statement: double alpha[10][5]; The number of components of alpha is ____.

50

The include used for the stream manipulators is

<iomanip>

The ______ operator always follows the cin object, and the ______ operator follows the cout object. Selected Answer:

>> , <<

What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 1; j <= 5; j++) cout << list[j] << " "; cout << endl;

Code result s in index out of bounds

Application software is the programs that manage the computer hardware and the programs that run on them.

False

Byte is made up of 16 consecutive bits.

False

Directives must end with a semicolon.

False

The following C++ expression produces a float result. cout << 3 / 2;

False

The following code segment displays: 1 cout << false;

False

The following will compile: char c = "a";

False

Using your knowledge of DeMorgan's Rule, will the following conditional statements yield the same result? bool a, b, c; cout << ( a && b || !c && !a) << endl; cout << !(!a || !b && c || !a) << endl;

False

After the first character you may use alphabetic characters, numbers, or underscore characters.

True

An algorithm is a set of well-defined steps for performing a task or solving a problem.

True

Classic C-Strings end with the null terminator, the '\0' character.

True

In C++ the following relationship regarding type size is always true for all platforms.

True

Syntax is the rules of grammar that must be followed when writing a program.

True

The CPU has 2 main parts: The Control Unit Arithmetic Logic Unit

True

The following code segment displays: Hi int x = 2, y = 1; if (x < y); cout << "Hi";

True

The following definitions in the same program is syntactically correct. int MyVar; int myVar

True

The type of a floating-point number defaults to being signed.

True

Unsigned integers always treat the highest bit (sign bit) as a magnitude part of the number.

True

Volatile memory is deleted when the computer is turned off.

True

he following code segment displays: This is true! Th-That's all folks! int x = 5; if ( x = 2 ) cout << "This is true! "; else cout << "This is false! "; cout << "Tha-Thats all folks!";

True

Array elements must __________ before a binary search can be performed.

be sorted

Assume you have the following declaration int beta[50]; Which of the following is a valid element of beta ?

beta[0]

A __________ search is more efficient than a __________ search.

binary, linear

A file __________ is a small holding section of memory that file-bound information is first written to.

buffer

Which of the following correctly declares name to be a character array and stores "William" in it?

char name[8] = "William";

What does the following display. int i = 1; cout << i++;

depends on compiler

Consider the following declaration: char charArray[51]; char discard; Assume that the input is: Hello There! How are you? What is the value of discard after the following statements execute? cin.get(charArray, 51); cin.get(discard);

discard = '\n'

A function can only have one return statement.

false

A function can return by name many parameters.

false

A while loop is a post test loop.

false

Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference.

false

For portability, in C++ the size of a type is always the same on different platforms.

false

Given the declaration int list[20]; the statement list[12] = list[5] + list[7]; updates the content of the twelfth component of the array list .

false

If an array index goes out of bounds, the program always terminates in an error.

false

Suppose list is a one-dimensional array of size 25, wherein each component is of type int . Further, suppose that sum is an int variable. The following for loop correctly finds the sum of the elements of list . sum = 0; for (int i = 0; i < 25; i++) sum = sum + list;

false

The lifetime of a local variable exists until the program ends.

false

The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0.

false

Values passed to function are parameters.

false

In row order form, the ____.

first row is stored first

if sales is an array of 50 components of type double, which of the following correctly initializes the array sales ?

for (int j = 0; j < 49; j++) sales[j] = 0;

If list is an array of 10 components of type int, which of the following codes correctly outputs all the elements of list ?

for (int j = 0; j <= 9; j++) cout << list[j] << " ";

Data that is to be sorted in ascending order is ordered.

from lowest value to highest value

In a for statement, this expression is executed only once.

initialization

Which of the following statements declares alpha to be an array of 25 components of the type int ?

int alpha[25]

Which of the following correctly declares and initializes alpha to be an array of four rows and three columns with the component type int ?

int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};

Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables?

int temp = num2; num2 = num1; num1 = temp;

A(n) __________ search uses a loop to sequentially step through an array.

linear

Consider the statement int list[10][8]; Which of the following about list is true?

list has 10 rows and 8 columns

A binary search begins with the __________ element of an array.

middle

A collection of a fixed number of elements (called components) arranged in n dimensions (n >= 1) is called a(n) ____.

n-dimensional array

This I/O manipulator in a cout stream is used to establish a field width for the value immediately following it.

setw()

Consider the following declaration: char str[15]; Which of the following statements stores "Blue Sky" into str ?

strcpy(str, "Blue Sky");

To write information to a file, use the

stream insertion objecy

Given the following declaration: int j; int sum; double sale[10][7]; which of the following correctly finds the sum of the elements of the fourth column of sale ?

sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[j][3];

Given the following declaration: int j; int sum; double sale[10][7]; which of the following correctly finds the sum of the elements of the fifth row of sale ?

sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[4][j];

Which of the choices of code segments executes and produces the same result as the following code segment ? int i=2; if ((i == 1) || (i == 2)) cout << "Here 1" << endl; else if (i == 3) cout << "Here 2" << endl;

switch (i) { case 1: case2: cout << "here 1" << endl; break; case 3: cout << "Here 2" << endl; break;

To write data to a file, you define an object of the __________ data type.

ofstream

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

opened

A __________ algorithm is a method of locating a specific item of information in a larger collection of data.

search

A driver tests a function by calling it using various arguments and checking return values.

true

A function must have a body to compile correctly.

true

A local variable is defined inside a function and is not accessible outside the function.

true

A scope of a parameter is the function in which it is in the functions parameter defintion.

true

A stub is a function with an empty body.

true

A while loop cannot be used as a fixed iteration loop.

true

For a reference parameter, any changes to the parameter variable inside the function also changes the matching argument.

true

In a two-dimensional array, the elements are arranged in a table form.

true

The binary search repeatedly divides the portion of an array being searched in half.

true

The one place where C++ allows aggregate operations on arrays is the input and output of C -strings.

true

When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter.

true

Will the following code compile without errors. cout << "Here I Am" << endl;

true


Ensembles d'études connexes

PrepU Chapter 2: Critical Thinking in Health Assessment

View Set

Патанатомия экзамен

View Set

Flexibility Training - Odsseyware

View Set

Maternal Newborn ATI Practice 2019 A

View Set

Chapter 25: Assessment of Cardiovascular Function

View Set

Molecular Genetics Ch. 19 - Learnsmart

View Set

Pediatric Success - Chapter 10 - Hematological/Oncology Disorders

View Set

BOT2673- Medical Insurance Billing

View Set