Midterm Material

Ace your homework & exams now with Quizwiz!

The programming language C++ evolved from ____.

C

Using functions greatly enhances a program's readability because it reduces the complexity of the function main.

True

Which of the following is a valid C++ statement?

typedef int integer;

The ____ rules of a programming language tell you which statements are legal, or accepted, by the programming language.

syntax

What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl;

35 45 10

Suppose that x is an int variable, y is a double variable, and z is an int variable. The input is: ​ 15 76.3 14 ​ Choose the values after the following statement executes: ​ cin >> x >> y >> z;

x = 15, y = 76.3, z = 14

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

2 3 0 1 2 3

Consider the following statements: ​ string str = "ABCDEFD"; string::size_type position; ​ After the statement position = str.find('D'); executes, the value of position is ____.

3

The value of the expression 33/10, assuming both values are integral data types, is ____.

3

*MIDTERM* What is the next Fibonacci number in the following sequence? ​ 1, 1, 2, 3, 5, 8, 13, 21, ...

34

Which of the following is an allowable aggregate operation on struct variables?

Assignment

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

char name[8] = "William";

Consider the following statements. struct circleData { double radius; double area; double circumference; }; circleData circle; Which of the following statements is valid in C++?

cin >> circle.radius;

Which of the following statements creates an anonymous type?

enum {A, B, C, D, F} grades;

Suppose that 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] << " "; cout << endl;

In structs, you access a component by using the struct name together with the relative position of the component.

False

In the statement cin >> x;, x can be a variable or an expression.

False

Which of the following statement about function prototypes and function headers is true?

Function prototypes end with a semicolon, but function headers do not.

Consider the following statements: string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is ____.

"BCDE"

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ What is the value of ch3 after the following statements execute? ​ cin.get(ch1); cin.get(ch2); cin.get(ch3);

'B'

In C++, the ____ symbol is an operator, called the member access operator.

.(dot)

*FINAL* What is the output of the following code? ​ enum courses {ALGEBRA, BASIC, PASCAL, PHILOSOPHY, ANALYSIS}; courses registered; registered = ALGEBRA; cout << registered << endl;

0

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

The length of the string "Hello There. " is ____.

13

*An operator that has only one operand is called a unique operator.

False

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

False

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

False

*MIDTERM* The maximum number of significant digits in float values is up to 6 or 7.

True

A function can return a value of the type struct.

True

Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly.

True

The control statements in the for loop include the initial statement, loop condition, and update statement.

True

The following is a legal C++ enumeration type: ​ enum colorType {BLUE, GREEN, PINK, YELLOW, RED};

True

The loop control variable in a flag-controlled while loop is a bool variable.

True

To access a structure member (component), you use the struct variable name together with the member name; these names are separated by the dot (period) operator.

True

Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____.

alpha = beta; beta = beta + 1;

Typically, in a program, a struct is defined ____ in the program.

before the definitions of all the functions

*Which executes first in a do... while loop?

body of the loop

In a loop, the ____ statement can be used to eliminate the use of certain (flag) variables.

break

A sequence of eight bits is called a ____.

byte

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}};

Consider the following function prototype: ​ int seqSearch(const listType& list, int searchItem); ​ The formal parameter _____ cannot modify the corresponding actual parameter.

list

What executes immediately after a continue statement is executed in a while and do-while loop?

loop-continue test

In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s).

looping

The components of a struct are called the ____ of the struct.

members

A(n) ____ consists of data and the operations on those data.

object

Which of the following is a legal identifier?

program_1

____ is a parameterized stream manipulator.

setfill

An array name and its index are separated using ____.

square brackets

Which of the following statements generates a random number between 0 and 50?

srand(time(0)); num = rand() % 50;

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

strcpy(str, "Blue Sky");


Related study sets

Spanish 1 - Ch. 1.1 - Subject Pronouns

View Set

mental health practice questions

View Set

Niermann ALL Multiple Choice (Exact Questions and Answers): Tests 1-4

View Set

Lección 4 Contextos - Guadalajara - lógico or ilógico?

View Set

ATI TEAS: unit 2 practice problems

View Set