Chapter 3: Understanding StructureTRUE/FALSE 1. Structured programs use spaghetti code logic. ANS: F PTS: 1 REF: 84 2. In a selection structure, you perform an action or task, and then you perform the next action in order. ANS: F PTS: 1 REF: 86 3. Repetition and sequence are alternate names for a loop structure. ANS: F PTS: 1 REF: 88 4. In a structured program, any structure can be nested within another structure. ANS: T PTS: 1 REF: 94 5. A structured program must contain a sequence, selection, and loop structure. ANS: F PTS: 1 REF: 94 6. Because you may stack and nest structures while retaining the overall structure, it might be difficult to determine whether a flowchart as a whole is structured. ANS: T PTS: 1 REF: 96 7. As a general rule, an eof question should always come immediately after an input statement because the end-of-file condition will be detected at input. ANS: T PTS: 1 REF: 100 8. Structured programming is sometimes called goto-less programming. ANS: T PTS: 1 REF: 101 9. No matter how complicated it is, any set of steps can always be reduced to combinations of the two basic structures of sequence and loop. ANS: F PTS: 1 REF: 110 10. The case structure is a variation of the sequence structure and the do loop is a variation of the while loop. ANS: F PTS: 1 REF: 110 MULTIPLE CHOICE 1. Programs that use _____ code logic are unstructured programs that do not follow the rules of structured logic. do b. nested ANS: A PTS: 1 REF: 87 4. get number while number is positive add to sum get number a. sequence c. loop sequence ANS: C PTS: 1 REF: 86 3. loop ANS: C c. The following pseudocode is an example of a ____ structure. case b. loop b. decision d. spaghetti d. decision d. sequence problem d. do loops c. single-alternative selections d. while d. nested ANS: B PTS: 1 REF: 87 5. loop b. dual-alternative selections ANS: D PTS: 1 REF: 88 7. nested . then c. ordered structure c. decision d. sequence c. Fill in the blank in the following pseudocode: if someCondition is true then do oneProcess ____ do theOtherProcess a. a.a. repetition b. sequence c. With a(n) ____. and then you perform the next action. nested PTS: 1 REF: 84 2. you perform an action or task. in order. loop b. if firstNumber is bigger than secondNumber then print firstNumber else print secondNumber a. get firstNumber get secondNumber add firstNumber and secondNumber print result a. if-else examples can also be called ____ because they contain the action taken when the tested condition is true and the action taken when it is false. else ANS: D PTS: 1 REF: 87 6. The following pseudocode is an example of a ____ structure. The following pseudocode is an example of a ____ structure. a. sequence structure b. Placing a structure within another structure is called ____ structures. do stepA do stepB if conditionC is true then do stepD else do stepE endif while conditionF is true do stepG endwhile a. nesting c. Attaching structures end to end is called ____ structures. selection d. You may hear programmers refer to looping as ____. . stacking d. loop internals b. iteration b. execution c. stacking d. You can use an ____ statement to clearly show where the actions that depend on a decision end. loop body c. The action or actions that occur within a loop are known as a(n) ____. The following pseudocode is an example of ____. a. case ANS: C PTS: 1 REF: 88 9. stacking d. a posttest ANS: B PTS: 1 REF: 89 11. action body d. building ANS: B PTS: 1 REF: 89 12. linking c. if conditionA is true then do stepE else do stepB do stepC do stepD endif a. a. nesting b. stacking d. a. nesting c. a posttest b. nesting c.ANS: C PTS: 1 REF: 88 8. single alternative structures b. a. shelling b. selecting ANS: A PTS: 1 REF: 90 14. The following pseudocode is an example of ____. structure body ANS: A PTS: 1 REF: 88 10. a pretest ANS: A PTS: 1 REF: 90 13. exit points only d. declaration c. spaghetti bowl d. a. restructuring b. end b. a. entry or combination points ANS: C PTS: 1 REF: 94 18. and loop ANS: C PTS: 1 REF: 94 17. Structures can be stacked or connected to one another at their ____. sequences ANS: B PTS: 1 REF: 101 22. a. priming ANS: B PTS: 1 REF: 102 . next b. priming ANS: D PTS: 1 REF: 98-99 19. Structured programs can be easily broken down into routines or ____ that can be assigned to any number of programmers. a. A structured program includes only combinations of the three basic structures: ____. go to ANS: D PTS: 1 REF: 101 21. entry or exit points b. The priming read is an example of a(n) ____ task. sequence. segments c. go next d. and loop c. selection.a. selection ANS: C PTS: 1 REF: 100 20. units b. In older languages. and loop d. housekeeping b. a. spaghetti code c. a. five ANS: B PTS: 1 REF: 93 16. exit d. modules d. iteration. selection. and loop b. endif PTS: 1 REF: 90 15. endloop d. three b. posttest b. a. The maximum number of entry points that any programming structure can have is ____. sequence. zero c. One way to straighten out an unstructured flowchart segment is to use the ____ method. a. loop c. selection. one d. identification. endstructure ANS: D c. iteration. A ____ read is an added statement that gets the first input value in a program. nested c. stacked d. you could leave a selection or loop before it was complete by using a ____ statement. entry points only c. The case structure is a variation of the ____ structure. ANS: block PTS: 1 REF: 90 4. A loop must return to the ____ question at some later point in a structure. A group of statements that execute as a single unit are called a(n) ____________________. start loop c. while ANS: B PTS: 1 REF: 104 c. the statements that start and end a structure are always on the same level and always in pairs. ANS: if-then-else if then else PTS: 1 REF: 87 3. ANS: sequence PTS: 1 REF: 86-87 2. ANS: goto go to go-to . Structured programming is sometimes called ____________________-less programming. loop-controlling d. continue loop ANS: B PTS: 1 24. Some people call the selection structure a(n) ____________________ statement. ANS: nest PTS: 1 REF: 91 5. selection c. master loop b. but there is no option to branch off and skip any of the tasks. do ANS: A PTS: 1 REF: 110 COMPLETION 1.23. if-then-else b. a. a. The do loop is a variation of the ____ loop. sequence while b. When you ____________________ structures. case d. A(n) ____________________ can contain any number of tasks. sequence REF: 110 25. d. a. 3. developers often find it easier to abandon the existing program and start from scratch. this costs more money. 6. decision structure e. ANS: . and. Define the term structure as it relates to programming. module d. 5. null case f. Such programs are so difficult to alter that when improvements are required. you take one of two courses of action Continue to repeat actions while a condition remains true An added statement that gets the first input value in a program Placing a structure within another structure A case in which nothing is done Attaching structures end-to-end Often can be used in multiple programs A variation of the selection structure 1. 10. j. stacking structures spaghetti code loop structure case structure nesting structures 1. 7. Why does spaghetti code have a shorter shelf life than structured code? ANS: Software developers say that spaghetti code has a shorter life than structured code. Logically snarled program statements A basic unit of programming logic With this. structure b. priming read c. This means that programs developed using spaghetti code exist as production programs in an organization for less time. a. 6. 4. 8. 5. i. 7. 9. 9. 2. Obviously. 3.PTS: 1 REF: 101 MATCHING Match each term with a statement below. depending on the answer. h. 8. you ask a question. g. 4. ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: G A D H B J E F C I PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: 1 1 1 1 1 1 1 1 1 1 REF: REF: REF: REF: REF: REF: REF: REF: REF: REF: 84 86 87 88 98 90 88 89 101 110 SHORT ANSWER 1. 10. PTS: 1 REF: 86 TOP: Critical Thinking 2. 2. In the most common type of loop. and loop. Placing a structure within another structure is called nesting structures. can be constructed using one or more of only three structures. What are the characteristics of a structured program? ANS: • A structured program includes only combinations of the three basic structures: sequence. In other words. and loop. any sequence. A structure is a basic unit of programming logic. PTS: 1 REF: 89-90 TOP: Critical Thinking 6. ANS: In a loop structure. Attaching structures end-to-end is called stacking structures. two. or loop. can be combined in an infinite number of ways. PTS: 1 REF: 88 TOP: Critical Thinking 4. • Structures can be stacked or connected to one another only at their entry or exit points. a condition is evaluated. All logic problems can be solved using only these three structures: sequence. mathematicians proved that any program. you continue to repeat actions while a condition remains true. selections. This continues until the condition becomes false. selection. of course. each structure is a sequence. • Any structure can be nested within another structure. if the answer is true. no matter how complicated. or loops. What are two general ways structures can be combined? ANS: You can have a sequence of tasks followed by a selection. you can diagram any task. selection. you execute the loop body again and then reevaluate the original condition. from doubling a number to performing brain surgery. . you can have a sequence of three tasks on one side of a selection. • Each structure has a single entry point and a single exit point. selection. or loop can contain other sequences. Rewrite the following as a while loop: do pay bills while more bills remain to be paid ANS: pay bills while there are more bills to pay pay bills endwhile PTS: 1 REF: 88-89 TOP: Critical Thinking 5. Besides stacking structures. With these three structures alone. you execute the loop body and evaluate the condition again. For example. If the condition is still true. PTS: 1 REF: 86 TOP: Critical Thinking 3. you can replace any individual tasks or steps in a structured flowchart diagram or pseudocode segment with additional structures. or a loop followed by a sequence. The action or actions that occur within the loop are known as the loop body. You can diagram each structure with a specific configuration of flowchart symbols. or all three types of structures. The three structures. Describe a loop structure. selection. and then you exit the structure.In the mid-1960s. Any structured program might contain one. if the answer to the question results in the loop being entered and the loop statements executing. and Java enforce structure by their syntax. that is. picture the flowchart as a bowl of spaghetti that you must untangle. It’s the way things are done professionally. and looping. PTS: 1 REF: 101 TOP: Critical Thinking 9. Newer languages such as C#. or future. even programs that use those older languages can be written in a structured form. Older languages. In a loop. as well as other programmers. • Modularity—Structured programs can be easily broken down into routines or modules that can be assigned to any number of programmers. Imagine you can grab one piece of pasta at the top of the bowl and start pulling. you can untangle the separate paths until the entire segment is structured. What are the three basic structures and how can they be used? ANS: No matter how complicated it is. selection. and then the flow comes back together. Describe how you can straighten out an unstructured flowchart segment. then the logic returns to the question that started the loop. As you “pull” each symbol out of the tangled mess. As programs get bigger. present. Additionally. • Efficiency—Most newer computer languages are structured languages with syntax that lets you deal efficiently with sequence. the question that controls the loop is always asked again. and loop. When the body of a loop executes. However. and structured programming is expected on the job today. • Maintenance—You. any set of steps can always be reduced to combinations of the three basic structures of sequence. selection. . PTS: 1 REF: 102 TOP: Critical Thinking 10. the logic goes in one of two directions after the question. and RPG. • Professionalism—All other programmers (and programming teachers you might encounter) expect your programs to be structured. often a module can be used in multiple programs. were developed before the principles of structured programming were discovered. will find it easier to modify and maintain structured programs as changes are required in the future. The routines are then pieced back together like modular furniture at each routine’s single entry or exit point. C++. Why is it best to use only three programming structures? ANS: • Clarity—The number-doubling program is a small program. the question is not asked a second time within the structure. These structures can be nested and stacked in an infinite number of ways to describe the logic of any process and to create the logic for every computer program written in the past. such as assembly languages. saving development time in the new project. COBOL. Explain the difference between the representation of a decision structure and a loop in a flowchart. ANS: In a selection structure. PTS: 1 REF: 96 TOP: Critical Thinking 8. they get more confusing if they’re not structured.PTS: 1 REF: 94 TOP: Critical Thinking 7. ANS: One way to straighten out an unstructured flowchart segment is to use the “spaghetti bowl” method. PTS: 1 REF: 110 TOP: Critical Thinking .