An Example showing the comparison between the lengths of a program estimated by both Halstead’s formula & Shooman’s formula( or Zipf’s

Length ) and the actual length of it
/* Indranil Nandy MTech, CSE Roll : 06CS6010 hi_i_am_indranil@yahoo.com /* On the basis of our suggestive definition of operators and operands of a program for the languages C, C++ and JAVA submitted in the previous assignment titled “HALSTEAD’s Operators and Oerands” we are exploiting the following program code to “find the factorial of a number” written in C to compare between the actual length of the program and the estimated length by both Halstead’s formula and Shooman’s formula. Here is the program code : /* this program calculates the factorial of a number*/ #include <stdio.h> long int factorial(int x); main( ) { int x; long int result; printf(“Enter the number”); scanf(“%d”, &x); result = factorial( x ); printf(“factorial of %d is %ld”, x, result); } /* returns the factorial of x */ long int factorial( int x ) { if ( x == 0) return 1; else return x * factorial(x-1); } The estimated length calculation goes as follows : Set of unique operators : { #, include, main, factorial, <>, ( ), {}, ;, ,, “”, printf, scanf, &, =, ==, if-else, *, - ,return} So η1 : 19

Set of unique operands : { stdio.h, int, long int, x, result, enter the world, %d, factorial of %d is %ld, 1} So η2 : 9 N1: Total number of operators used = 43 N2: Total number of operands used = 21 So, actual length of the program is Na : N1 + N2 = 64. So, with Halstead’s formula, estimated length : NH = η1 log2 η1 + η2 log2 η2 = 109.23 So, with Shooman’s formula (or Zipf’s length), estimated length :

NS = (η1 + η2) [0.5772 + ln (η1 + η2)] = 109.46 The result is shown in a tabular form :
Program objective factorial(x ) η1 19 η2 9 N1 43 N2 21 Na 64 NH 109.23 NS 109.46

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.