Halstead Software Science

Sunil Kumar 06IT6012

Indranil Nandy

&

06CS6010

Guidelines for C: 

Comments are not considered. Identifier and function declarations are not considered.
As an example, func(a,b);-----here func, a and b are considered operands and ‘,’ and ‘;’ operators as it is calling a function, but for the following case we do not treat func, a and b as operands int func(int a , int b) { ……. ……. }

Hash directives are considered.

Operators: 

Function calls. All looping statements like for(), while() etc. All control statements like if(), if()-else etc. Control construct switch ().

   

Keywords words. Brackets, commas and terminator. Goto. All operators like arithmetic, logical etc. ‘.’ and ‘->’.

Operands: 

All variables and constants. Local variables with same names in different functions are considered as unique operands. Labels.

Array name is counted as operands. Structure-name, member-name Same names of member element in different structure variable are considered as unique operands.

 

Guidelines for C++ and JAVA:  

All C guidelines are also considered. :: operator. Class object and member elements are considered as operands. Call to member function by class object is considered as operator.

Default parameter assignments are not counted, e.g., class Point { Point(int x = 0,int y = 0); }; -----------is not counted. new and delete considered same as the function calls, mainly because they are equivalent to the function calls. There are two extra operators in JAVA : >>> and >>>+ -------each is considered a single operator.

Explicit List of Operands & Operators

 

In C : Operands : Tokens of the following categories are all counted as operands : IDENTIFIER : all identifiers that are not reserved words TYPENAME (type specifiers) : Reserved words that specify type: int, float, char, double, long, short, signed, unsigned, void. This class also includes some compiler specific nonstandard keywords. CONSTANT : Character, numeric or string constants.

Operators : Tokens of the following categories are all counted as operators : SCSPEC (storage class specifiers) : Reserved words that specify storage class: auto, extern, register, static, typedef.. TYPE_QUAL (type qualifiers) : Reserved words that qualify type: const, final, volatile. RESERVED Other reserved words of C: break, case, continue, default, do, if, else, enum, for, goto, if, new, return, sizeof, struct, switch, union, while. This class also includes some compiler specific nonstandard keywords. OPERATOR : ! != % %= & && || &= ( ) { } [ ] * *= + ++ += , - -- - = - > . / /= : :: < << <<= <= = == > >= >> >>= ? ^ ^= | |= ~ ; =& “ “ ‘ ‘ # ##

Operators in C++ & JAVA
  

Operands are more or less same in C++ and JAVA as in C. So we are specifying only the operands list in C++ and JAVA. Tokens of the following categories are all counted as operators : SCSPEC (storage class specifiers) Reserved words that specify storage class: auto, extern, register, static, typedef, virtual, mutable, inline. TYPE_QUAL (type qualifiers) Reserved words that qualify type: const, friend, volatile, final. RESERVED Other reserved words of C++ & JAVA: break, case, continue, default, do, if, else, enum, for, goto, if, new, return, asm, operator, private, protected, public, sizeof, struct, switch, union, while, this, namespace, using, try, catch, throw, abstract, concrete, const_cast, static_cast, dynamic_cast, reinterpret_cast, typeid, template, explicit, true, false. This class also includes some compiler specific nonstandard keywords OPERATOR ! != % %= & && || &= ( ) { } [ ] * *= + ++ += , - -- - = -> . / /= : :: < << <<= <= = == > >= >> >>= ? ^ ^= | |= ~ ; =& “ “ ‘ ‘ # ## ~

/* Program calculating addition or Subtraction of two integers */
#include <stdio.h> int add(int, int); int sub(int, int); void main() { int a, b, result; printf(“Enter First no : ”); scanf(“%d”, &a); printf(“Enter Second no : ”); scanf(“%d”, &b); if(a>b) result=sub(a,b); else result=add(a,b); printf(“RESULT = %d”,result); }

int sub(int c, int d) { int e; e=c-d; return(e); } int add(int c, int d) { int e; e=c+d; return(e); }

Operator main {} printf scanf if-else > = add sub + return ; , η1= 14

Occurrence 1 3 3 2 1 1 4 1 1 1 1 2 11 2 N1=34

Operands Main function a b result Add function c d e Sub function c d e η2= 9

Occurrence 4 4 3

1 1 2

1 1 2 N2=19

N (program length)

= N1+N2 = 34+19 = 53 = η1 log2 η1 + η2 log2 η2 = 14 log2 14 + 9 log2 9 =81.8 = (η1+η2)[0.5772 + ln(η1+η2)] = (14+9)[0.5772 + ln(14+9)] = 85.4

Nh (Halstead estimated length)

Ns (shooman estimated length)

Thank you……….