Você está na página 1de 16

Halstead Software Science

Sunil Kumar Indranil Nandy


06IT6012 & 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 Occurrence Operands Occurrence
main 1 Main function
{} 3 a 4
printf 3 b 4
scanf 2 result 3
if-else 1
> 1 Add function

= 4 c 1
add 1 d 1
sub 1 e 2
+ 1
- 1 Sub function
return 2 c 1
; 11 d 1
, 2 e 2
η1= 14 N1=34 η2= 9 N2=19
N (program length) = N1+N2
= 34+19
= 53

Nh (Halstead estimated length) = η1 log2 η1 + η2 log2 η2


= 14 log2 14 + 9 log2 9
=81.8

Ns (shooman estimated length) = (η1+η2)[0.5772 + ln(η1+η2)]


= (14+9)[0.5772 + ln(14+9)]
= 85.4
Thank you……….

Você também pode gostar