CS2 Q2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The flow of this structure depends on the instructions given to the computer

Sequence structure

The Switch-selection structure is a _____-selection structure

multi/multiple

Used in situations where you need to evaluate multiple conditions

nested decision statement

The default in the switch control structure is executed when?

no case matches the value of the expression

This structure is also called a looping structure or loops

repetition structure

Decision structure is also called?

selection structure or conditionals

The IF selection structure is a ______-selection structure

single

True and false are not variable names nor string but are _______ _________ and in fact are ________ _____

special constants, reserved words

Nested IF Statement

statement placed inside another if statement

compound statements

statements with more than one line

Does not require the evaluation of a logical expression

switch case

With this selection structure, programs can have multiple options on which set of statements to execute.

switch case

It either ignores or selects a set of actions

IF selection structure (2)

assignment operator

=

Conditions take the form of (except for SWITCH Selection Structures)?

Boolean

Logical expressions may be in any form such as:

- Boolean variable or constant - A variable/value followed by a relational operator followed by another variable/value - Logical expression followed by a logical operator followed by a logical expression

Rules in Switch Case

1. The program can only choose one case per execution of the switch statement. 2. The value of the variable will determine the case selected. 3. Expression must evaluate to an integral type of value. 4. The data type and the case value must be the same. 5. Case value must also be an integral data type. It cannot contain another expression. 6. At the end of the statements inside the case is a break. 7. Each time the switch statement is executed: a. An expression is evaluated. b. Case values are evaluated, starting with the first value. c. The first case value that matches the expression will be executed. d. Statements execute until a break keyword is encountered. 8. If no case value matches the value of the expression, then the default case is chosen and executed.

In C++, which operator is used to check for equality in an IF statement?

==

relational operator

==

Decision structure/selection structure/conditionals

Directs the computer to make a decision and take the appropriate action based on that decision

Sequence Structure

Directs the computer to process the program instructions in the order listed in the source code

Repetition Structure

Directs the computer to repeat one or more instructions until some condition is met, at which time the computer should stop repeating the instructions

TRUE OR FALSE: If a decision statement is already inside another decision statement, you can no longer place another one inside it.

FALSE

TRUE OR FALSE: Switch statements allow boolean expressions

FALSE

TRUE OR FALSE: You cannot add IF statements to ELSE and ELSE IF statements

FALSE

True or False: In C++, the IF statement is used for iteration control flow.

FALSE

True or False: The ELSE has a condition

FALSE

True or False: The IF statement in C++ can only be used to compare two values and make a decision based on the result.

FALSE

TRUE OR FALSE: In the code snippet below, Statement 1 will be executed. int x = 4; if(x > 5) { if(x < 10) { //Statement 1 } }

FALSE, x=4 is not greater than 5 therefore statement 1 will not execute

It is used to specify the conditions in which a statement or group of statements should be executed or not.

IF selection structure

In the __-____ statement, when the condition is true, it will execute the statement or group of statements, while if the condition is false, the other statements or block of statements are executed.

IF-ELSE

Chooses between two courses of action and can either go to only one

IF/ELSE Selection Structure (2)

Integral type declare

Integer values

Which of the following statements is true about the selection control structure in C++?

It allows a program to execute different blocks of code based on the evaluation of a condition.

Which of the following best describes the role of the IF statement in C++ programming?

It is used to control the flow of a program based on a condition

Selection can be classified into

One-way (single) selection Two-way (double) selection Multi-selection or Compound Block

IF/ELSE Selection Structure

Performs an action if a condition is true and performs a different action if the condition is false

IF Selection Structure

Performs an action if a condition is true or skips the action and continues with the series of statements

SWITCH Selection Structure

Performs one of many different actions depending on the value of an integer expression

Which of the following represents a control structure in C++ that allows a program to execute a block of code repeatedly based on the evaluation of a condition?

Repetition

In C++, the basic control structures are the following

Repetition Selection Sequence

Which of the following control structures in C++ allows a program to execute different blocks of code based on the evaluation of a condition?

Selection

It is a control structure that chooses its flow of control based on two or more options.

Selection (Branching) control structure

Selects the action to perform from many different actions

Switch Selection Structure (2)

It is a type of selection structure that selects the action to perform from many different actions.

Switch-selection structure

TRUE OR FALSE: It is possible to place ELSE statements inside an IF block.

TRUE

TRUE OR FALSE: It is possible to place IF statements inside an ELSE block.

TRUE

TRUE OR FALSE: Nested IF statements can be referred as the inner IF and the original if statement as the outer IF.

TRUE

The IF statement in C++ can only be used to execute a block of code if a specified condition is true.

TRUE

True or False: A semicolon after the if condition and before statements will yield the program a syntax error

TRUE

True or False: The IF statement in C++ allows for the execution of different code blocks based on specified conditions.

TRUE

TRUE OR FALSE: In the code snippet below, Statement 1 will be executed. int x = 7; if(x > 5){ if(x < 10){ //Statement 1 } }

TRUE, 7 is greater than 5 and less than 10. Therefore, statement 1 will execute

In C++, what is the purpose of the IF statement in decision control flow?

To execute a block of code only if a specified condition is true.

Selection (Branching) Control Structure

When we want the execution of some statements in the program to be based on conditions

characters

automatically converted to an integer value by compiler

What are found at the end of statements in the switch control structure?

break; (break statement)

nested decision statement

decision statement placed inside another decision statement

The IF/ELSE Selection Structure is a ______-selection structure

double

The program goes to ____ if the condition of if results to true

else

fail-safe portion of ladder

else

0 (in Boolean values) is equivalent to?

false

if statement form

if (boolean_expression) statement;

In C++, the IF statement is used for decision control flow to execute a certain block of code based on a specified condition. Which of the following best represents the syntax for the IF statement in C++?

if (condition) {

IF statement real-life examples

if it is raining outside, bring an umbrella if the storm signal is #2, there is no classes if you are thirsty, drink something if your gas is empty, fill up

An IF-ELSE structure should start with an __ block followed by the ____ block

if, else

Members of an enumerated type

interpreted as integer by compiler


संबंधित स्टडी सेट्स

Chapter 2: The Environment: Made up of the General and task Environments

View Set

AP English Lang and Composition Unit 6 Progress Check MCQ

View Set

Texas Law of Contracts - Chapter 3

View Set

Concepts 139/167 Review Questions

View Set