You are on page 1of 5

Experiment 9

AIM: - To calculate token count and measure of a program.

Theory: -
The major drawback with LOC measure is that some lines are more difficult to code than others.
A program is considered to be a series of tokens and if we count the number of tokens, some
interesting results may emerge.
Generally, any symbol or keyword in a program that specifies an algorithmic action considered
an operator, while a symbol used to represent data is considered an operand. Punctuation
marks are also categorized as operator.
Halstead Program Length: -The total number of operator occurrences and the total number of
operand occurrences.
N = N1 + N2
Estimated Program Length: - The length of well-structured program is a function only of the
number of unique operators and operands. This function is called estimated length equation
^
N=η1 log η 1+η 2 log η2
The following alternate expressions have been published to estimate program length:
NJ = log(η 1!) + log(η 2!)
NB = η 1 log η2+ η2 log η 1
NC = η 1* sqrt(η 1) + η 2 * sqrt(η 2)
NS = (η* logη) / 2
Halstead Vocabulary: – The total number of unique operator and unique operand occurrences.
η=η 1+ η 2
Program Volume: – Proportional to program size, represents the size, in bits, of space
necessary for storing the program. This parameter is dependent on specific algorithm
implementation.
V = N*log(η)
Potential Minimum Volume: – The potential minimum volume V* is defined as the volume of
the most succinct program in which a problem can be coded.
V* = (2+η 2)* log¿)
Program Level: – To rank the programming languages, the level of abstraction provided by the
programming language, Program Level (L) is considered. The higher the level of a language, the
less effort it takes to develop a program using that language.
L = V* / V
The value of L ranges between zero and one, with L=1 representing a program written at the
highest possible level (i.e., with minimum size).
And estimated program level is

^L= 2∗η 2
η 1∗N 2
Program Difficulty: – This parameter shows how difficult to handle the program is.
D=1/L
Estimated program difficulty
η 1∗N 2
D=
^
2∗η 2
Programming Effort: – Measures the amount of mental activity needed to translate the existing
algorithm into implementation in the specified program language.
η1∗N 2∗N∗logη
E=V/L=D*V=
2∗η 2
Language Level: – Shows the algorithm implementation program language level. The same
algorithm demands additional effort if it is written in a low-level program language. For
example, it is easier to program in Pascal than in Assembler.

λ=L∗V ¿ =L2∗V
Programming Time: – Shows time (in second) needed to translate the existing algorithm into
implementation in the specified program language.
T =E /β
Here β called stroud number ranges between 5 and 20 and E is effort.

Code
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n1,n2,N1,N2;
cout<<"Enter no. of unique operators (n1) : ";
cin>>n1;
cout<<"Enter no. of unique operands (n2) : ";
cin>>n2;
cout<<"Enter occurrence of operators (N1) : ";
cin>>N1;
cout<<"Enter occurrence of operands (N2) : ";
cin>>N2;
float N,Nstar,n,V,Vstar,L,Lcap,D,E,lem,T;
N=N1+N2;
Nstar=(n1*log(n1)+n2*log(n2))/log(2);
n=n1+n2;
V=N*log(n)/log(2);
Vstar=(2+n2)*log(2+n2)/log(2);
L=Vstar/V;
D=1/L;
Lcap=2*n2/(n1*N2*1.0);
E=V/Lcap;
lem=L*Vstar;
T=E/18;
cout<<endl;
cout<<"Program Length (N) : "<<N<<endl;
cout<<"Estimated Program Length (N^) : "<<Nstar<<endl;
cout<<"Halstead Vocabulary (n) : "<<n<<endl;
cout<<"Program Volume (V) : "<<V<<endl;
cout<<"Potential Minimum Volume (V*) : "<<Vstar<<endl;
cout<<"Program Level (L) : "<<L<<endl;
cout<<"Estimated Program Level (L^) : "<<Lcap<<endl;
cout<<"Program Difficulty (D) : "<<D<<endl;
cout<<"Programming Effort (E) : "<<E<<endl;
cout<<"Language Level : "<<lem<<endl;
cout<<"Programming Time (T) : "<<T<<endl;
return 0;
}
Output

Conclusion
Through this experiment, we learnt how to calculate token count for a program.

You might also like