An Example Showing The Comparison Between The Lengths Of A Program Estimated By Both Halstead (by Indranil Nandy)

  • Uploaded by: Indranil Nandy
  • 0
  • 0
  • August 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View An Example Showing The Comparison Between The Lengths Of A Program Estimated By Both Halstead (by Indranil Nandy) as PDF for free.

More details

  • Words: 343
  • Pages: 2
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 [email protected] /* 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

η1

η2

N1

N2

Na

NH

NS

objective factorial(x

19

9

43

21

64

109.23

109.46

)

Related Documents


More Documents from "Indranil Nandy"