Describe The Theory With Programming Examples The Selection Control Statements in C+ +. Answer
Describe The Theory With Programming Examples The Selection Control Statements in C+ +. Answer
Describe the theory with programming examples the selection control statements in C+
+.
Answer-
The algorithm you are developing may need to do some actions based upon a decision.
For example, an algorithm that is evaluating a formula can check to see if a number is negative
before taking the square root of that number and then proceed differently depending on whether
the result will be a normal number or a complex number. Another example is processing grades.
If the grade is above 90%, an A is assigned to the student, between 80% and 90%, a B is
assigned to the student, and so on.
There need not be a statement 2a or a statement 2b. Either path could be empty or could contain
several statements. It would be silly for both of them to be empty (or both have the exact same
statements), as your decision, Yes or No, would have no effect (nothing different would happen
based on the decision).
The exact decision you write down affects whether the Yes or No paths are taken. It is very easy
to change the decision to switch the yes and no paths. For example, on the left below is a simple
decision on whether a student’s GPA makes the grade for being on the Dean’s list. On the right
are two different rephrasings of the decision such that the No path is taken if the student is on the
Dean’s list. Some people prefer the version on the left and some the version on the top right.
Very few prefer the bottom right because of the double negative implicit in the decision.
F-1
F-2
F-3