Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Since it is a structured program, the rules you can follow are ... * A program w

ID: 3878406 • Letter: S

Question

Since it is a structured program, the rules you can follow are ...

* A program with no conditions has a CFG with three nodes (including the start and end nodes) and two edges and V(G) = 2-3+2(1)=1.

Using: V(G)= E-N+2p

* The addition of each if-then-else statement increases the number of nodes (N) by 3 and edges (E) by 4.

* The addition of each if-then or while statement increases the number of nodes (N) by 2 and edges (E) by 3

* Thus, the net increase in cyclomatic complexity is 1 for each decision in the program.

With that in mind, what is the cyclomatic complexity V(G) of the following program?

b) For the following structured program P2, calculate the cyclomatic complexity using the structured program decision count rule. Show your work. Program P2 1)integer A, B; 2) input (A) 4) if (A > 7) 5) 7) 8) else 9) 10) B=2; if(A7 14) 15) while (1-1 ; 1

Explanation / Answer

As per the given rules:

1.A program with no condition has cyclomatic complexity as 1
2. One if-else or while or if-then-else increases the complexity by 1.

As per the given rules:
1.A program with no condition has cyclomatic complexity as 1
2. One if-else or while or if-then-else increases the complexity by 1.
In the given code we start with no condition :
Initial cyclomatic complexity is 1
Code is having a if-else(line 4) (Introducing this the complexity will be ) - 1 + 1
Code is having a if-else(line 11) (Introducing this the complexity will be ) - 1 + 1 + 1
Code is having a while loop(line 15) (Introducing this the complexity will be) - 1 + 1 + 1 + 1
The while loop is also having a if-else(line 17) statement(Introducing this the complexity will be)
= 1 + 1 + 1 + 1 + 1= 5