Which of the following encompasses the other three?

4.2 Control Structures

Böhm and Jacopini"s research1 demonstrated that all programs could be created in terms of just 3 control structures, namely, the sequence structure, the selection structure and also the repetition structure. The term "regulate structures" comes from the area of computer scientific research. When we introduce C++"s implementations of manage frameworks, we"ll describe them in the terminology of the C++ traditional document2 as "regulate statements."

Sequence Structure in C++

The sequence framework is developed into C++. Unmuch less directed otherwise, C++ statements execute one after the other in the order in which they are written—that is, in sequence. The Unified Modeling Language (UML) task diagram of Fig. 4.1 illustprices a typical sequence structure in which 2 calculations are percreated in order. C++ allows us to have actually as many type of actions as we desire in a sequence structure. As we"ll shortly see, anywhere a solitary activity may be placed, we may location a number of actions in sequence.

You watching: Which of the following encompasses the other three?


*

Fig. 4.1 Sequence-structure activity diagram.


In this number, the 2 statements involve including a grade to a full variable and also including 1 to a respond to variable. Such statements can show up in a routine that averages a number of student qualities. To calculate an average, the total of the grades is separated by the variety of grades. A counter variable would be supplied to store track of the number of worths being averaged. You"ll watch similar statements in the regimen of Section 4.6.

Activity diagrams are part of the UML. An activity diagram models the workflow (additionally dubbed the activity) of a section of a software application system. Such workflows might encompass a section of an algorithm, such as the sequence framework in Fig. 4.1. Activity diagrams are composed of special-function icons, such as action state symbols (a rectangle with its left and also best sides reinserted via arcs curving outward), diamonds and also tiny circles; these icons are linked by transition arrows, which represent the flow of the activity. Activity diagrams aid you develop and also represent algorithms. As you"ll check out, task diagrams clearly show how manage frameworks operate.

Consider the sequence-structure activity diagram of Fig. 4.1. It includes two activity states that recurrent actions to percreate. Each activity state includes an action expression— e.g., "add grade to total" or "include 1 to counter"—that specifies a particular activity to perdevelop. Other actions can include calculations or input/output operations. The arrows in the activity diagram are dubbed shift arrows. These arrows reexisting transitions, which show the order in which the actions stood for by the action states occur—the routine that implements the activities portrayed by the task diagram in Fig. 4.1 first adds grade to full, then adds 1 to respond to.

The solid circle situated at the optimal of the activity diagram represents the activity"s initial state—the beginning of the workflow before the regimen percreates the modeled tasks. The solid circle surrounded by a hollow circle that shows up at the bottom of the activity diagram represents the final state—the finish of the workflow after the regimen performs its tasks.

See more: " They Say I Say 3Rd Edition With Readings Ebook, They Say / I Say

Figure 4.1 also consists of rectangles through the upper-right corners folded over. These are referred to as notes in the UML. Notes are explanatory remarks that describe the objective of symbols in the diagram. Notes deserve to be used in any UML diagram—not simply task diagrams. Figure 4.1 offers UML notes to show the C++ code connected via each action state in the task diagram. A dotted line connects each note with the element that the note explains. Activity diagrams normally carry out not present the C++ code that implements the activity. We usage notes for this objective below to show exactly how the diagram relates to C++ code. For even more indevelopment on the UML, see our optional situation study, which shows up in the Software Engineering Case Study sections at the ends of Chapters 1–7, 9 and also 13, or visit www.uml.org.

Selection Statements in C++

C++ provides three types of selection statements (questioned in this chapter and also Chapter 5). The if selection statement either percreates (selects) an action if a condition (predicate) is true or skips the action if the problem is false. The if...else selection statement percreates an activity if a condition is true or percreates a various activity if the condition is false. The switch selection statement (Chapter 5) performs among many various actions, depending on the value of an integer expression.

The if selection statement is a single-selection statement because it selects or ignores a single activity (or, as we"ll shortly watch, a single team of actions). The if...else statement is dubbed a double-selection statement bereason it selects in between two various actions (or groups of actions). The switch selection statement is called a multiple-selection statement bereason it selects among many type of various actions (or teams of actions).

Repetition Statements in C++

C++ gives three forms of repetition statements that allow programs to percreate statements consistently as lengthy as a problem continues to be true. The repetition statements are the while, do...while and also for statements. (Chapter 5 presents the execute...while and also for statements.) The while and also for statements perdevelop the activity (or team of actions) in their bodies zero or even more times—if the loop-extension problem is initially false, the activity (or team of actions) will not execute. The execute...while statement performs the action (or group of actions) in its body at leastern once.

See more: B And C Question 27 1 According To Our Lectures, Goals Should Be:

Each of the words if, else, switch, while, do and for is a C++ keyword. These words are scheduled by the C++ programming language to implement various functions, such as C++"s regulate statements. Keywords should not be used as identifiers, such as variable names. Figure 4.2 gives a finish list of C++ keywords.