CMPSC TEST 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

ordinal value

(int, short, long char, or bool).

Match the operator with the appropriate definition. A. && B. || C. ! 1. Combines two conditional operands with the logic that if both are true, the result of the combined condition is true. 2. "Flips" the result of its lone conditional operand. If the operand is true, the result of applying the operator is false, and vice-versa. 3. Combines two conditional operands with the logic that if at least one of the conditions is true, the result of the combined condition is true.

1. A 2. C 3. B

Match the given selection construct with the type of selection. A. Multi-way selection B. Two-way selection (explicit) C. Two-way selection (implied) 1. If Statement 2. If-Else Statement 3. Cascading If Statement OR Switch Statement

1. C 2. B 3. A

If p is a Boolean variable, which of the following logical expressions always has the value false? A) p && p B) p || p C) p && !p D) p || !p E) b and d above

C) p && !p

After execution of the following code, what will be the value of angle if the input value is 10? cin >> angle; if (angle > 5) { angle = angle + 5; } else if (angle > 2) { angle = angle + 10; } A) 0 B) 5 C) 10 D) 15 E) 20

D) 15

these errors are detected by the C++ compiler and involve errors in the use of the language. Examples include misspelled keywords and missing semicolons.

Syntax Error

name, return type, parameters

function header

In C++, subprograms are referred to as:

functions

[ means...

inclusive

The operators &&, ||, and ! are known as _______________ operators.

logical, boolean

) means...

non-inclusive

The value in a controlling expression must be of an ______________ type

ordinal

A Switch statement, like an If statement, is a conditional _____________ control structure.

selection

The manipulator ______________ lets us control how many character positions the next data item should occupy when it is output.

setw

a set of instructions written in a programming language.

Source Code

allow us to shorten the code we write.

Standard Namespace

The value of the C++ expression 11 + 22 % 4 is: A) 13 B) 1 C) 8 D) 16 E) None of the above.

A) 13

If a C++ If statement begins with if (age = 30) Then the condition is an assignment expression, not a relational expression. A) True B) False

A) True

If the code fragment if (a >= 10) if (a < 20) a = a + 2; else a = a + 1; is indented according to the manner in which it is executed, the correct indentation is if (a >= 10) if (a < 20) a = a + 2; else a = a + 1; A) True B) False

A) True

In C++, a block (compound statement) is not terminated by a semicolon. A) True B) False

A) True

In C++, the value of the expression 3 + 2 * 6 is 15. A) True B) False

A) True

The code segment: if (speed<=40) cout << "Too Slow"; if (speed > 40 && speed <= 55) cout << "Good Speed"; if (speed >55) cout << "Too fast"; could be rewritten (with the same effect) as: if (speed <=40) cout << "Too slow"; else if (speed <= 55) cout << "Good speed"; else cout << "Too fast"; A) True B)False

A) True

What is the screen output for the following code segment? int x = 7; int y = 4; if ( y < 6) { x = x + 1; cout << x; } if ( x == 7) { y = y + 1; } cout << y; A) 84 B) 78 C) 7<space>4 D) 4<space>7

A)84

What is the value of the expression (sum), assuming sum is an int variable containing the value 5? A) True B) False

A)True

a step-by-step procedure to solve a problem. Usually written in English or in "pseudocode" (English-like instructions).

Algorithm

operators which perform an arithmetic operation on two operands. In C++, the main arithmetic operators are +, -, *, /, and %.

Arithmetic Operators

a C++ statement which places a specific data value into a variable. Put another way, a single data value is assigned to a variable.

Assignment Statement

A "switch" controlling expression can be of any simple data type. A) True B) False

B) False

Every if-else if (cascading if) statement must have an else clause. A) True B) False

B) False

In a C++ expression without parentheses, all operations are performed in order from left to right. A) True B) False

B) False

The C++ compiler considers the identifier CanOfWorms to be the same as the identifier canofworms. A) True B) False

B) False

The expression !(n < 5) is logically equivalent to the expression n > 5. A) True B) False

B) False

An if-else if (cascading if) statement is an example of _____________ selection. A) Two-way B) Multi-way C) One-way D) Six-way

B) Multi-way

true or false

Boolean

_______________ are expressions which evaluate to one of two possible values: true or false.

Booleans

Which of the following is NOT a C++ relational operator? A) == B) < C) && D) !=

C) &&

If the int variables int1 and int2 contain the values 4 and 5, respectively, then the value of the expression float(int1 / int2) is: A) 0.8 B) 0 C) 0.0 D) 1 E) 1.0

C) 0.0

What is the screen output of the following code? int p = 5 + 7/2; switch (p) { case 5: cout << 'a'; break; case 7: cout << 'b'; break; case 8: cout << 'c'; break; default: cout << "None of the above"; }

C) c

English phrases intermingled with source code to show the intent of one or more lines of code. In C++, comments are differentiated from source code by adding two forward slashes at the beginning of a comment.

Comments

the time during which the compiler is analyzing the C++ code for errors and translating the code into a machine-executable form.

Compile-time

executed at compile-time

Compiler Directives

a C++ statement that contains multiple statements within it.

Compound Statement

a C++ language construct that permits alternate sections of code to be executed based on a conditional (true/false) test.

Conditional Selection

expressions which evaluate to one of two possible values: true or false

Conditions

Which of the following statements about the C++ main function is FALSE? A) Every program must have a function named main. B) Program execution begins with the first executable statement in the main function. C) The word int in the function heading means that the main function returns an integer value (to the operating system). D) The main function must call (invoke) at least one other function.

D) The main function must call (invoke) at least one other function

Which C++ logical expression correctly determines whether the value of beta lies between 0 and 100? A) 0 < beta < 100 B) 0 < beta && beta < 100 C) (0 < beta) && (beta < 100) D) b and c above E) a, b, and c above

D) b and c above

(2 points) What is the screen output of the following code: int x = 5; int y = 8; if ( x != 5 ) { y = 7; x = x + y; } else { y = 4; x = x - y; } cout << x; A) 13 B) -3 C) 12 D) 1

D)1

After execution of the following code, what will be the value of angle if the input value is 10? cin >> angle; if (angle > 5) { angle = angle + 5; } else { angle = angle + 10; } A) 0 B) 5 C) 10 D) 15 E) 25

D)15

a C++ keyword which identifies the type of data stored within a C++ variable. A data type also defines the legal set of operations that can be performed with values and variables of that type.

Data Type

a method of checking your algorithm for correctness whereby you walk through the algorithm step-by-step without the use of a computer.

Desk Check

Which one of the following is NOT a valid identifier in C++? A) CAPS B) UpAnDdOwN C) Hi_There D) top40 E) 3BlindMice

E) 3BlindMice

A combination of literals, variables, and operators which can be evaluated to a single value. Usually found on the right-hand side of an assignment statement.

Expression

code statements for the function

Function Body

small, discrete segments of C++ code that perform simple tasks. Functions in C++ take zero or more inputs and can produce only a single output, often called a return value.

Functions

a piece of data that enters a program and/or function, either through the code instructions themselves or through user interaction with the program.

Input

a specific piece of data, such as a character (e.g. @ or E), a string (e.g. "Hello World") or a number (e.g. 34).

Literal

A combination of five things (Algorithm Name, Problem Input(s), Problem Output, Relevant Formula(s), and Algorithm) which detail the data required to solve the problem, the output expected, and the step-by-step process required to transform the given input into the expected output.

Logic Specification

these errors are mistakes in the algorithm which cause it to produce invalid results.

Logic error

binary operators which test the relationship between two conditional values (or expressions). In C++, the operators are && and ||. These operators produce a Boolean result when applied to two operands. There is also a unary operator (!).

Logical Operators

the process of assigning a piece of the computer's main memory for use by a program. This occurs when a variable is declared: a specific piece of main memory is allocated for use by the program and is associated with the requested variable name.

Memory allocation

a C++ language construct that permits alternate sections of code to be executed based on a conditional (true/false) test. In C++, a cascading if statement allows for the checking of many different conditions, one after another, until one is found with a true value. Each block of code can be called a branch; which branch is executed is decided by which conditional expression has a true value.

Multi-Way Branching

a C++ variable, expression, or literal that can be used with a C++ operator. For example, in the expression 3+5, the numbers 3 and 5 are operands and the + symbol is the operator.

Operand

a C++ symbol which allows a specific operation to be performed on one or more operands.

Operator

____________ are useful when you are trying to find an exact match; the "case" values are the possible matches

Ordinal Values

data that is shown to the user via some device, normally a monitor

Output

one of the built-in data types in C++, such as int, float, or char.

Primitive Data Type

binary operators which test the relationship between two values. In C++, the operators are ==, !=. >, <, >=, and <=. These operators produce a Boolean result when applied to two operands.

Relational Operators

the result of a function's execution, delivered back to the code which initiated the function.

Return Value

the time during which the computer is executing a C++ program.

Run-Time

language or logic errors which manifest themselves as program "crashes" during execution.

Run-Time Error

the standard flow of control in C++, or the way in which statements are executed. A program executes starting with the first statement in the main() function and terminates with the last statement in main(), if all goes well. Individual expressions are executed left-to-right.

Sequential execution

named memory locations that store a particular type of data. Used for temporary storage by a C++ program.

Variable

a C++ statement that requests an allocation of memory for use as temporary storage. Requires both a data type and a variable name, though it can also include an initial value to store in memory

Variable Declaration

In C++, the ____________ statement causes an immediate exit from the Switch statement in which it appears.

break;


Kaugnay na mga set ng pag-aaral

Chapter 5: The production process & costs

View Set

uceusa road rules review test questions (FLORIDA)

View Set

seab physics test 2 pre assignments

View Set

Managment business unit 1 review

View Set

TEST 2 - 3.PE. p.27. Ex.4 First day in the office/ TS.- 2.28 /English File Elementary

View Set

NUR 337 - Week 1: IV Catheter Insertion

View Set

Lab 1-1 : Linux installation and configuration

View Set

PEDS Neurological questions, Peds neuro, Ch. 48 Musculoskeletal or Articular Dysfunction, Chapter 49: Neuromuscular or Muscular Dysfunction, Chapter 45: Cerebral Dysfunction

View Set

Chapter 9, chapter 10, PM Chapter 11

View Set

Chapter 13 - Services: The Intangible Product (Smartbook)

View Set

Postoperative Nursing Management (NC1)

View Set