WEEK 3 DQ 2 PRG 211
* What are the similarities and differences between single alternative structures, dual alternative structures, and case structures? Provide an example of one of the three control structures using pseudocode. Try to provide an example that has not already been posted.
Selection structures ask a question and, depending on the answer, take one of two courses of action. Then, no matter which path is followed, they continue on the next task. Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops. A single-alternative structure is a single block of statements to be executed or skipped. When a single alternative selection structure returns the value of true, the actions on the true branch of the structure are executed. If the expression returns false, no actions are executed and the program control continues to the next executable statement structure in the program. Dual-alternative structures contain two blocks of statements, one of which is to be executed, while the other one is skipped. A case structure executes one sub diagram depending on the input value passed to the structure. Only one sub diagram is visible at a time, and the structure executes only one case at a time. Case structures easily support multiple simple conditions that have similar actions compared to if/else statements.
Single-alternative structure example –
If Age >=18 Set Eligibility = “Yes”
End if
DQ 2
Write a 200- to 300-word response to the following question: What is an iteration structure? What problem does a repetition structure solve? Provide an example of a process in which a repetition structure is appropriately used.
Iteration Structure means the action of repeating a process usually with the objective of approaching a desired goal, target or result. Each repetition of the process is called an "iteration," and the results of one iteration are used as the starting point for the next iteration.
Repetition structures are used when something needs to be repeated a certain number of times through the use of a "loop". A loop is simply a statement that completes iterations or cycles until a certain value is reached. Once the test expression has been met, execution moves to the next executable statement. Such as, if you were to request the user to enter ten values to find the average of the numbers, you could write a loop that would continue letting the user enter numbers until ten numbers had been entered. The number of times a task is repeated is continuously a substantial part of any repetition structure...but it is completely in the hands of the user to know how many times a loop will be continuously repeated to make certain that the task is performed correctly. Loops, looping, iteration and repetition, are all terms used identically, and mean essentially the same thing when describing/explaining repetition structures, but iteration is above all and directly tied to counting through a number of loops.
EXAMPLE:
Nick brush your teeth = 0
Nick brush your teeth = 0
Nick brush your teeth = 0
= cavities
int i = 0; for (i; i < 5; i++){ //counter i starts at 0 and increments by 1 for each loop until i = 5 cout << i;
}