CS C++ Control Structures

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

Double-Selection Structure

Selects between two different actions. (If/else)

Single-Selection structure

Selects or ignores a single action. (If)

Multiple-Selection Structure

Selects the action to perform from many different actions. (Switch)

Three types of control structures

Sequence structure, selection structure and repetition structure

Flowchart: Connector symbols

Small circle symbols for drawing only a portion of an algorithm.

C++ seven types of control structures

sequence, three types of selection and three types of repetition

Executable statements

those that are executed when the program has been converted from pseudocode to C++ and is run. Declarations are not these.

Conditional Operator

( ? : ) C++'s only ternary operator, it takes the three operands. The operands together with the conditional operator form a conditional expression. The first operand is the condition, the second operand is the value for the entire conditional expression if the condition is true and the third operand is the value for the entire conditional expression if the condition is false. For example: cout << ( grade >= 60 ? "Passed" : "Failed" ); this evaluates to the string "Passed" if grade >= 60 and "Failed" if condition is false.

Algorithm

A procedure for solving a problem in terms of the actions to be executed and the order in which these actions are to be executed

Top

A single statement in top down stepwise refinement that conveys the overall function of the program. Rarely contains enough information to code the entire C++ program.

Top down stepwise refinement

A technique that is essential to the development of well-structured programs.

Total

A variable used to accumulate the sum of a series of values. Should be initialized to zero before start of program.

While repetition structure

Action will be performed repeatedly while the condition remains true.

Nonfatal Logic error

Allows a program to continue executing but the program produces incorrect results.

Goto statement

Allows the programmer to specify a transfer of control to one of a very wide rang of possible destinations in a program.

Sentinel Value

Also called a signal value, dummy value, flag value. Indicates end of data entry. User types in values until all have been entered, then type in this value to indicate last value has been entered. Also called indefinite repetition.

Pseudocode

An artificial and informal language that helps programmers develop algorithms. Similar to everyday English, is convenient and friendly although it is not an actual computer programming language. Helps programmers "think out" a program. Consists only of executable statements.

Program failing

Called "bombing" or "crashing"

Syntax error

Caught by the compiler, error in the computer language.

Fatal logic error

Causes a program to fail and terminate prematurely

Second refinement

Commits to specific variables.

Uninitialized Variable

Contains a "garbage" value (also called an undefined value) - the value last stored in the memory location reserved for that value.

Unary cast operator

Creates temporary values that are floating point values.

Float

Data type to handle numbers with decimal points.

Bool

Data type to represent true and false. The keywords true and false are used to represent values of this.

Flowchart: Decision symbol

Diamond symbol that indicates a decision is to be made.

Refinement

Divide the top into a series of smaller tasks and list these in the order in which they need to be performed. There are multiple versions of these that go into further detail each time.

If selection structure

Either performs (selects) an action if a condition is true or skips the action if the condition is false.

Action/decision model of programming

Flowcharts only contain rectangle symbols to indicate actions to be performed and diamond symbols to indicate decisions to be made.

Arrows in flowcharts

Flowlines

Flowchart

Graphical representation of an algorithm or of a portion of an algorithm. Drawn using certain special-purpose symbols such as rectangles, diamonds, ovals, and small circles.

Logic error

Has its effect at execution time.

Three selection structures

If, If/else, Switch

Flowchart: Oval symbol

In complete algorithm, this symbol containing the word "Begin" is the first symbol and containing the word "End" is the last symbol. When drawing only a portion of an algorithm, these are omitted for small circle symbols.

Three phases of programs.

Initialization phase, processing phase (inputs data and adjusts program variables accordingly) and termination phase (calculates and prints final results)

Int

Integer data types

First refinement

Lists tasks in order they need to be completed.

Control structure nesting

Only other way control structures may be connected besides stacking.

If/else selection structure

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

Switch selection structure

Performs one of many different actions depending on the value of the expression.

Pseudocode or Flowcharts

Pseudocode is strongly preferred by most programmers.

Flowchart: Action symbol

Rectangle symbol indicates any type of action including a calculation or an input/output operation.

Program control

Specifying the order in which statements are to be executed in a computer program.

Sequential execution

Statements in a program are executed one after the other in the order in which they are written.

Counter-controlled repetition

Uses a variable called a counter to control the number of times a set of statements will execute. Often called definite repetition because number of repetitions is known before the loop begins executing.

Transfer of Control

Valid C++ statements enable the programmer to specify that the next statement to be executed may be other than the next one in sequence.

Truncated

When fractional part of value is lost.

Three Repetition Structures

While, do/while, for.

C++ ignores these

Whitespace characters like blanks, tabs and newlines used for indentation and vertical spacing.

C++ keywords

Words reserved by the language to implement various features such as C++'s control structures. May not be used as identifiers such as for variable names.

Single-entry/single-exit control structures

control structures are attached to one another by connecting the exit point of one control structure to the entry point of the next. Control-structure stacking.

More popular version of nested if/else structures

if (condition) do this else if (condition) do this else if (condition) etc. This avoids deep indentation

Examples of C++ keywords

if, else, switch, while, do, for, break, continue, try, delete, operator, class, false, namespace, bool, new, true


Kaugnay na mga set ng pag-aaral

Intro to Construction Drawings-Part 3

View Set

Greek and Roman mythology in the Harry Potter books Greek

View Set

Success in College and Life - Website Evaluation

View Set

N524 EAQ #6 Fundamentals Of Nursing: Fundamental Skills

View Set

Growth and Development peds final test

View Set

ATI Mobility & Tissue Integrity Quiz

View Set

Real Estate Appraisal: Income Approach to Value Part 2 Selecting an Overall Cap Rate

View Set