Wednesday, November 6, 2019
Brown essays
Brown essays A selection group consists of a test and two sets of one or more operations (statements). The test must be stated so that it yields a true or false result. One set of statements is performed when the outcome of the test is true. The other set is performed when the outcome is false. The flowchart in Figure 5-1 illustrates the flow of control through a selection group. The two sets of statements are mutually exclusive; that is, only one is performed. The next statement to be performed is then the statement following the selection group. There is a special case of the selection group in which the false case is null-that is, contains no statements. When the false case is null, a false result simply causes an exit from the selection group, and no statements are executed. This type of selection group is illustrated in Figure 5-2. The key words if, then, and else are used for selection. End if is placed at end (bottom) of the selection group. The general structure is shown in Figure 5-3. It is very important that the Figure 5-1 Flowchart of the general from of the selection group. Statement in the THEN and ELSE sets be indented under their corresponding key words so that each that each stands out clearly from the other. Figure 5-2. Flowchart of a selection group having a null false case. If the ELSE set is null, it is simply omitted, as shown in figure 5-4 Figure 5-3 General form of the selection group in pseudocode. The boxes represent sets of one or more statements. Figure 5-4 General form of the selection group in pseudocode when the else case is null. The box represents sets of one or more statements. (Solutions precede the exercises at the end of the chapter.) 5-1. Construct an If- then-else that instructs the computer to print the message There is no sales tax if the tax code is zero and The sales tax is 4% otherwise. 5-2. Construct an if-then-else that instructs the computer to add 1 to freshman counter if classif...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.