0% found this document useful (0 votes)
45 views9 pages

Class Test Sasindhar

The document provides information about a class test for a software engineering course, including 3 questions that calculate cyclomatic complexity for code snippets. The answers show that question 1 has a complexity of 2, question 2 has a complexity of 2, and question 3 has a complexity of 3, as determined by analyzing the nodes, edges, and connected components in each code snippet according to the cyclomatic complexity formula.

Uploaded by

siddardtha666666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views9 pages

Class Test Sasindhar

The document provides information about a class test for a software engineering course, including 3 questions that calculate cyclomatic complexity for code snippets. The answers show that question 1 has a complexity of 2, question 2 has a complexity of 2, and question 3 has a complexity of 3, as determined by analyzing the nodes, edges, and connected components in each code snippet according to the cyclomatic complexity formula.

Uploaded by

siddardtha666666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

SAVEETHA SCHOOL OF ENGINEERING

SAVEETHA INSTITUTE OF MEDICAL AND TECHNICAL SCIENCES

Institute of Computer Science &Engineering

Sub Code: CSA10 Subject NName: Software Engineering

Year: II, III,


Branch: CSE & IT
IV
Course Outcomes
1. Recall the attributes of well-engineered software.

2. Identify the appropriate process model for suitable software product development.

3. Interpret the requirements, analysis, design of product and able to test it with recent software
development tools.

4. Test the software for its quality using various testing tools as per the framework.

5. Demonstrate the new product with existing component-based development and perform
configuration management.

Blooms Taxonomy Levels (BTL)


1. Remembering 2. Understanding 3. Applying 4. Analysing 5. Evaluating 6. Creating

Class Test
Q.No Questions Marks CO BTL
1. Calculate 10 1 4
cyclomatic
complexity for the
given code-

IF A = 354

THEN IF B > C
THEN A = B

ELSE A = C

END IF

END IF

PRINT A

2 Calculate 10 1 2
cyclomatic
complexity for the
given code-

{ int i, j, k;

for (i=0 ; i<=N ; i+


+)

p[i] = 1;

for (i=2 ; i<=N ; i+


+)

k = p[i]; j=1;

while (a[p[j-1]] >


a[k] {

p[j] = p[j-1];

j--;

p[j]=k;

3 Calculate 10 1 3
cyclomatic
complexity for the
given code-

begin int x, y,
power;

float z;

input(x, y);

if(y<0)
power = -y;

else power = y;

z=1;

while(power!=0)

{ z=z*x;

power=power-1;

} if(y<0)

z=1/z;

output(z);

end

ANSWERS
1. To calculate the cyclomatic complexity of the given code, we need to determine the number of
independent paths through the code. The formula for cyclomatic complexity is given by:

M = E - N + 2P

Where:

M = Cyclomatic complexity

E = Number of edges

N = Number of nodes

P = Number of connected components

In this case, let's break down the code into nodes, edges, and connected components:
Nodes:

1. IF A = 354

2. THEN IF B > C

3. THEN A = B

4. ELSE A = C

5. END IF

6. END IF

7. PRINT A

Edges:

1 -> 2 (Edge from node 1 to node 2)

2 -> 3 (Edge from node 2 to node 3)

2 -> 4 (Edge from node 2 to node 4)

3 -> 5 (Edge from node 3 to node 5)

4 -> 5 (Edge from node 4 to node 5)

5 -> 6 (Edge from node 5 to node 6)

6 -> 7 (Edge from node 6 to node 7)

Connected Components:

There is only one connected component in this code.

Now, let's calculate the values:

N = 7 (number of nodes)

E = 7 (number of edges)

P = 1 (number of connected components)

M = E - N + 2P
= 7 - 7 + 2(1)

=2

Therefore, the cyclomatic complexity of the given code is 2.

2. To calculate the cyclomatic complexity of the given code, we need to determine the number of
independent paths through the code. The formula for cyclomatic complexity is given by:

M = E - N + 2P

Where:

M = Cyclomatic complexity

E = Number of edges

N = Number of nodes

P = Number of connected components

In this case, let's break down the code into nodes, edges, and connected components:

Nodes:

1. Variable declaration (int i, j, k)

2. For loop initialization (i=0)

3. For loop condition (i<=N)

4. Assignment statement (p[i] = 1)

5. For loop update (i++)

6. For loop condition (i<=N)

7. Start of inner block

8. Assignment statement (k = p[i])

9. Assignment statement (j = 1)

10. While loop condition (a[p[j-1]] > a[k])


11. Assignment statement (p[j] = p[j-1])

12. Decrement statement (j--)

13. Assignment statement (p[j] = k)

Edges:

1 -> 2 (Edge from node 1 to node 2)

2 -> 3 (Edge from node 2 to node 3)

3 -> 4 (Edge from node 3 to node 4)

4 -> 5 (Edge from node 4 to node 5)

5 -> 6 (Edge from node 5 to node 6)

6 -> 7 (Edge from node 6 to node 7)

7 -> 8 (Edge from node 7 to node 8)

7 -> 13 (Edge from node 7 to node 13)

8 -> 9 (Edge from node 8 to node 9)

9 -> 10 (Edge from node 9 to node 10)

10 -> 11 (Edge from node 10 to node 11)

11 -> 12 (Edge from node 11 to node 12)

12 -> 10 (Edge from node 12 to node 10)

Connected Components:

There is only one connected component in this code.

Now, let's calculate the values:

N = 13 (number of nodes)

E = 13 (number of edges)

P = 1 (number of connected components)

M = E - N + 2P
= 13 - 13 + 2(1)

=2

Therefore, the cyclomatic complexity of the given code is 2.

3. To calculate the cyclomatic complexity of the given code, we need to determine the number of
independent paths through the code. The formula for cyclomatic complexity is given by:

M = E - N + 2P

Where:

M = Cyclomatic complexity

E = Number of edges

N = Number of nodes

P = Number of connected components

In this case, let's break down the code into nodes, edges, and connected components:

Nodes:

1. Variable declaration (int x, y, power)

2. Variable declaration (float z)

3. Input statement (input(x, y))

4. If statement condition (y<0)

5. Assignment statement (power = -y)

6. Else statement

7. Assignment statement (power = y)

8. Assignment statement (z = 1)

9. While loop condition (power != 0)

10. Start of while loop


11. Assignment statement (z = z * x)

12. Assignment statement (power = power - 1)

13. End of while loop

14. If statement condition (y<0)

15. Assignment statement (z = 1/z)

16. Output statement (output(z))

Edges:

1 -> 2 (Edge from node 1 to node 2)

2 -> 3 (Edge from node 2 to node 3)

3 -> 4 (Edge from node 3 to node 4)

4 -> 5 (Edge from node 4 to node 5)

4 -> 6 (Edge from node 4 to node 6)

5 -> 8 (Edge from node 5 to node 8)

6 -> 7 (Edge from node 6 to node 7)

7 -> 8 (Edge from node 7 to node 8)

8 -> 9 (Edge from node 8 to node 9)

9 -> 10 (Edge from node 9 to node 10)

10 -> 11 (Edge from node 10 to node 11)

11 -> 12 (Edge from node 11 to node 12)

12 -> 9 (Edge from node 12 to node 9)

10 -> 13 (Edge from node 10 to node 13)

13 -> 14 (Edge from node 13 to node 14)

14 -> 16 (Edge from node 14 to node 16)

14 -> 15 (Edge from node 14 to node 15)

15 -> 16 (Edge from node 15 to node 16)

Connected Components:

There is only one connected component in this code.


Now, let's calculate the values:

N = 16 (number of nodes)

E = 17 (number of edges)

P = 1 (number of connected components)

M = E - N + 2P

= 17 - 16 + 2(1)

=3

Therefore, the cyclomatic complexity of the given code is 3.

You might also like