100% found this document useful (1 vote)
896 views

Halstead Software Science

This document contains questions and examples related to calculating complexity metrics for programs using the Halstead complexity measures. For different C programs provided, it defines the unique operators and operands, and calculates values for measures like program length (N), volume (V), difficulty (D), and effort (E). For functions in one C program, it lists the Halstead metric values calculated for each, including the number of unique operators and operands, length, volume, difficulty and effort.

Uploaded by

yusra22
Copyright
© Attribution Non-Commercial (BY-NC)
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
100% found this document useful (1 vote)
896 views

Halstead Software Science

This document contains questions and examples related to calculating complexity metrics for programs using the Halstead complexity measures. For different C programs provided, it defines the unique operators and operands, and calculates values for measures like program length (N), volume (V), difficulty (D), and effort (E). For functions in one C program, it lists the Halstead metric values calculated for each, including the number of unique operators and operands, length, volume, difficulty and effort.

Uploaded by

yusra22
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 2

Q uestion #1 Take the following program, for (int i=1; i<=n; i+=1) f*=i; define n1,n2,N1 and N2.

define n1 to be the number of unique operators, in the example there are 9: for ( int = ; <= += ) *= define n2 to be the number of unique operands, in the example there are 4: i1 n f define N1 to be the number of operators, in the example there are 11: for ( int = ; <= ; += ) *= ; define N2 to be the number of operands, in the example there are 8: i 1 i n i 1 f i define N, the length of the program to be N1+N2 define V, the volume of the program, to be N log2(n1 + n2) define D, the difficulty of the program, to be (n1 N2) (n2 2) define E, the effort required to write the program, to be DV (example 19) (example 70.31) (example 12) (example 632.79)

Question #2 Let us consider the following C program: main( ) { int a, b, c, avg; scanf(%d %d %d, &a, &b, &c); avg = (a+b+c)/3; printf(avg = %d, avg); } The unique operators are: main () {} int scanf & ; = + / printf The unique operands are: A b c &a &b &c a+b+c avg 3 %d %d %d avg = %d Therefore, 1 = 12, 2 = 11 Estimated Length = (12*log12 + 11*log11) = (12*3.58 + 11*3.45) = (43+38) = 81 Volume = Length*log(23) = 81*4.52 = 366

Question #3 Let us consider the following C program:a

#include <stdio.h> int twice (int a){ return 2*a; }

int max (int a, int b){ if (a > b) return a; return b; }

int f_switch(int a){ switch (a){ int f_nestedif(int a, int b){ case 0 : if (a*a < b*b) printf("zero"); if (a > 60) return max(a,b); case 10 : else if (b > 60) return 60; printf("an even number"); return b; break; } default: printf("I don't know that one"); int f_while(int a){ return -1; int i = 2; break; if (a < 0) return 0; } while (a > 0){ return 0; a -= 100; } i *= 2; } return i; } The Halstead metric values for these functions are as follows. Function twice() max() N1 5 9 N2 4 7 15 14 10 n1 4 5 9 10 8 n2 3 3 6 9 9 9 16 34 31 31 N V 25.3 48 132.8 131.7 126.7 L 0.3 0.2 3.6 6.4 7.2 2.7 5.8 11.25 7.8 4.4 D 67.4 280 1494.4 1024.2 563.1 Operands twice, a (2), 2 max, a (3), b (3) f_nestedif, a (5), b (6), 60,60,60 f_while, a (4), i (3), 2,2, 0,0,0, 100 f_switch, a (2), 0,0, 10, 1, "zero", "an even...", "I don't..." E

f_nestedif() 19 f_while() f_switch() Function twice() max() f_nestedif() 17 21

Operators int (2), return, *, semicolon int (3), if, >, return (2), semicolon (2) int (3), if (3), * (2), > (2), <, return (3), max(), else, semicolon (3) int (3), =, if, <, >, while, return (2), -=, *=, semicolon (5) int (2), switch, switch-case (3), -, printf (3), break (2), return (2), semicolon (7)

f_while()

f_switch()

You might also like