See the code below
READ mark;
IF(mark > 90)
GRADE = ‘A’;
ELSE IF(mark > 81 && mark < 90)
GRADE = ‘B’;
ELSE IF(mark > 71 && mark < 80)
GRADE = ‘C’;
ELSE IF(mark > 61 && mark < 70)
GRADE = ‘D’;
ELSE IF(mark < 60)
GRADE = ‘F’;
PRINT GRADE;
predict the number of independent paths to be tested.
The answer is 9. But how?
Answers & Comments
Answer:
In this code, there are a total of 5 independent paths that need to be tested, one for each of the 5 ELSE IF statements.
The independent paths are the sequences of statements that are executed when a particular condition is met. In this case, each ELSE IF statement has a condition that needs to be evaluated, and if the condition is true, the corresponding GRADE assignment statement will be executed.
For example, the first independent path is:
READ mark;
IF(mark > 90)
GRADE = ‘A’;
PRINT GRADE;
The second independent path is:
READ mark;
IF(mark > 90)
ELSE IF(mark > 81 && mark < 90)
GRADE = ‘B’;
PRINT GRADE;
And so on, until the fifth independent path:
READ mark;
IF(mark > 90)
ELSE IF(mark > 81 && mark < 90)
ELSE IF(mark > 71 && mark < 80)
ELSE IF(mark > 61 && mark < 70)
ELSE IF(mark < 60)
GRADE = ‘F’;
PRINT GRADE;
Each of these paths represents a different execution path through the code, depending on the value of the mark variable. Thus, there are a total of 5 independent paths in this code.
Answer:
There are five independent path.
IF(mark> 90)
GRADE = 'A';
ELSE IF(mark > 81 && marka 90)
GRADE = 'B',
ELSE IF(mark> 71 && mark < 80)
GRADE = 'C';
ELSE IF(mark> 61 && mark < 70)
GRADE - 'D':
ELSE IF(mark<60)
GRADE = 'F'; PRINT
GRADE Since in the code give there are total of five conditions given and all of them are independent. That is why it will five independent paths.