Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

DELHI

TECHNOLOGICAL
UNIVERSITY
SOFTWARE
ENGINEERING

HARSH THAKUR (2K19/SE/048)

Experiment-8

AIM: Develop program to find cyclomatic complexity


using DD path for :
(i) Roots of quadratic equation

Code:

# include<stlib.h>

(1) int main ( )

(2) {
(3) int a, b, c, d, boolean = 0;

(4) double D;

(5) printf (/n/t Enter 'a' coefficient :”);

(6) scanf (“%d”, &a) ;

(7) printf (“/n/t Enter 'b' coefficient :);

(8) scanf (“%&d”, &b);

(9) printf (/n/t Enter 'c' coefficient :);

(10) scanf, (“%d", &c) ;

(11) if ((a > =0) && (a < = 100) && (b > = 0) && (b < =100) && (c > =0) && (c <
=100)) {

(12) boolean = 1;

(13) if (a = = 0) {

(14) boolean = -1

(15) }
(16) }

(17) if (boolean = = 1) {

(18) d = b * b - 4 * a * c;

(19) if (d = = 0) {

(20) printf (“roots are equal and real r1= r2 = %f" b/(2 * float));

(21) }

(22) else if (d > 0) {

(23) D = sqrt (d);

(24) printf (“roots are real and are r1=%f and r2=%f" (-b – D)/(2 * a), (-b + D)/(2 *
a));

(25) }

(26) else {

(27) D = sqrt (-d) / (2 * a);

(28) printf (“roots are imaginary”);

(29) }

(30) }

(31) else if (boolean = = -1) {

(32) printf (“Not a quadratic equation”);

(33) }

(34) else {

(35) printf (“Invalid input range …");

(36) }
(37) getch ( ):

(38) return 0;

(39) }

Flow Graph:
DD Path Graph:
Since, nodes 1-10 are sequential nodes in the above flow graph, hence they
are merged together as a single node i.e.,a. Since node 11 is a decision node,
thus we cannot merge it any more. Likewise we can go on deciding the
merging of nodes & arrive.
We get following decision table.

Nodes in flow Corresponding Nodes of DD Path Justification


graph graph
1-10 a Sequential Nodes
11 b Decision Nodes
12 c Sequential Nodes
13 d Decision Nodes
14-15 e Sequential Nodes
16 f Three edges
Combined
17 g Decision Nodes
18 h Sequential Nodes
19 i Decision Nodes
20-21 j Sequential Nodes
22 k Decision Nodes
23-25 l Sequential Nodes
26-29 m Sequential Nodes
30 n Three edges
Combined
31 o Decision Nodes
32-33 p Sequential Nodes
34-36 q Sequential Nodes
37 r Three edges
Combined
38-39 s Sequential Exit Nodes
Calculation of Cyclomatic Complexity V(G):
V(G) = e – n + 2 ,

Here e are the number of edges and n are the number of nodes.

V(G) = 24 – 19 + 2
=7

Identification of the basis-set with Seven Paths


Path 1: a -> b -> f -> g -> n -> p -> q -> r

Path 2: a -> b -> f -> g -> n -> o -> q -> r

Path 3: a -> b -> c -> e -> g -> n -> p -> q -> r

Path 4: a -> b -> c -> d -> e -> g -> n -> o -> q -> r

Path 5: a -> b -> f -> g -> h -> i -> m -> q -> r

Path 6: a -> b -> f -> g -> h -> i -> k -> m -> q -> r

Path 7: a -> b -> f -> g -> h -> j -> l -> m -> q -> r

Conclusion

Each of these paths consists of at least one new edge. Hence this basis set of
paths is NOT unique.

Test cases should be designed for the independent path execution as


identified above.

We must execute these paths at least once in order to test the program
thoroughly.

(ii) Triangle classification problem

Code:
# include <stdlib.h>

(1) int main ( )

(2) {

(3) int a, b, c, boolean = 0;

(4) printf (“nt Enter side-a :”);

(5) scanf (“%d”, & a);

(6) printf(“nt Enter side-b :”);

(7) scanf (“%d”, & b);

(8) printf (“/n/t Enter side-c:”);

(9) scanf ("%d", & c);


(10) if ((a > 0) && (a < – 100) && (b > 0) && (b < . 100) && (c > 0) && (c
< =100)) {

(11) if ((a + b) > c) && ((c + a) > b) && ((b + c) > a)) {

(12) boolean = 1;

(13) }

(14) }

(15) else {

(16) boolean = -1;

(17) }

(18) if (boolean = = 1) {

(19) if ((a = =b) && (b = =c)) {


(20) printf (“Triangle is equilateral”);

(21) }

(22) else if ((a = =b) I I (b = = c) I I (c = = a)) {

(23) print (“Triangle is isosceles”);

(24) }

(25) else {

(26) printf("Triangle is scalene");

(27) }

(28) }

(29) else if (boolean = = 0) {


(30) printf (“Not a triangle”);

(31) }

(32) else

(33) printf (“n invalid input range”);

(34) }

(35) getch ( );

(36) return -1;

(37) }

Flow Graph:
DD Path Graph
Since, nodes 1-9 are sequential nodes in the above flow graph, hence they are
merged together as a single node a.

Likewise we can go on deciding the merging of nodes & arrive.

We get following decision table.


Nodes in flow Corresponding Nodes of DD Justification
graph Path graph
1-9 a Sequential Nodes
10 b Decision Nodes
11 c Decision Nodes
12-13 d Sequential Nodes
14 e Two edges Combined
15-17 f Sequential Nodes
18 g Three edges Combined and
Decision Node
19 h Decision Nodes
20-21 i Sequential Nodes
22 j Decision Nodes
23-24 k Sequential Nodes
25-27 l Sequential Nodes
28 m Three edges Combined
29 n Decision Nodes
30-31 o Sequential Nodes
32-34 p Sequential Nodes
35 q Three edges Combined
36-37 r Sequential Exit Nodes

Calculation of Cyclomatic Complexity V(G):


V(G) = e – n + 2 ,

Here e are the number of edges and n are the number of nodes.

V(G) = 23 – 18 + 2

=7
Identification of the basis-set with Seven Paths
Path 1: a -> b -> c -> e -> g -> n -> o -> q

Path 2: a -> b -> c -> d -> e -> g -> n -> o -> q

Path 3: a -> b -> f -> g -> n -> o -> q

Path 4: a -> g -> h -> i -> m -> q

Path 5: a -> g -> h -> j -> k -> m -> q

Path 6: a -> g -> h -> j -> l -> m -> q

Path 7: a -> b -> f -> g -> n -> p -> q

Conclusion

Each of these paths consists of at least one new edge. Hence this basis set of
paths is NOT unique.

Test cases should be designed for the independent path execution as


identified above.

We must execute these paths at least once in order to test the program
thoroughly.

You might also like