STMT Assignment 4

STMT Assignment 4

方向:计算机应用

学号:16340227

姓名:王永杰


1 计算题


1.1 计算下列代码片段的Halstead 复杂度的11项内容:

if (month < 3) { 
    month += 12;
    –year; 
} 
return dayray((int)(day + (month + 1) * 26/10 + year + year/4 + 6 * (year/100) + year/400)% 7); 
  • Sol:
  • 1> 求得 n 1 , N 1 , n 2 , N 2 n_1, N_1, n_2, N_2 n1,N1,n2,N2
operator Number of Occurrences
if 1
dayray 1
return 1
< 1
+= 1
- 1
+ 6
* 2
/ 4
% 1

n 1 = 10 , n 2 = 19 n_1 = 10, n_2 = 19 n1=10,n2=19

operand Number of Occurences
month 3
year 5
day 1
3 1
12 1
1 1
26 1
10 1
4 1
6 1
100 1
400 1
7 1

n 2 = 13 , N 2 = 19 n_2 = 13, N_2 = 19 n2=13,N2=19

  • 2> 求11项值
指标
程序词汇表长度
Program vocabulary
n = n 1 + n 2 n = n_1 + n_2 n=n1+n2
= 10 + 13 = 23 = 10 + 13 = 23 =10+13=23
程序长度
Program length
N = N 1 + N 2 N = N_1 + N_2 N=N1+N2
= 19 + 19 = 38 = 19 + 19 = 38 =19+19=38
程序的预测长度
Calculated program length
N ^ = n 1 log ⁡ 2 n 1 + n 2 log ⁡ 2 n 2 \hat N = n_1\log_{2}{n_1} + n_2\log_{2}{n_2} N^=n1log2n1+n2log2n2
= 10 ⋅ log ⁡ 2 10 + 13 ⋅ log ⁡ 2 13 = 10 \cdot \log_{2}{10} + 13 \cdot \log_{2}{13} =10log210+13log213
≈ 33.22 + 48.11 = 81.33 \approx 33.22 + 48.11 = 81.33 33.22+48.11=81.33
程序体积
Volume
V = N log ⁡ 2 n V = N\log_{2}{n} V=Nlog2n
= 38 ⋅ log ⁡ 2 23 ≈ 171.90 = 38\cdot\log_{2}{23} \approx 171.90 =38log223171.90
程序级别
Level
L ^ = 2 n 1 × n 2 N 2 \hat L = \frac{2}{n_1} \times\frac{n_2}{N_2} L^=n12×N2n2
= 2 10 × 13 19 ≈ 0.136842 =\frac{2}{10} \times \frac{13}{19} \approx 0.136842 =102×19130.136842
程序难度
Difficulty
D = 1 L ^ ≈ 7.31 D = \frac{1}{\hat L}\approx7.31 D=L^17.31
编程工作量
Effort
E = V × D = V L ^ E = V \times D = \frac{V}{\hat L} E=V×D=L^V
= 38 ⋅ log ⁡ 2 23 26 190 ≈ 1 , 256.16 = \frac{38\cdot\log_{2}{23}}{\frac{26}{190}}\approx1,256.16 =1902638log2231,256.16
语言级别 L ′ = L ^ × L ^ × V ≈ 0.08471 L{'} = \hat L \times \hat L \times V\approx 0.08471 L=L^×L^×V0.08471
编程时间
hours
T ^ = E S × f , S = 60 × 60 , f = 18 \hat T = \frac{E}{S\times f}, S = 60 \times 60, f = 18 T^=S×fE,S=60×60,f=18
T ^ ≈ 0.019385 \hat T\approx 0.019385 T^0.019385
平均语句大小 N 语 句 数 = 38 4 = 9.5 \frac{N}{语句数} = \frac{38}{4} = 9.5 N=438=9.5
程序中的错误数预测值 B = V 3000 = N log ⁡ 2 n 3000 B = \frac{V}{3000} = \frac{N\log_{2}{n}}{3000} B=3000V=3000Nlog2n
= 38 ⋅ log ⁡ 2 23 3000 ≈ 0.057298 = \frac{38\cdot \log_{2}{23}}{3000} \approx 0.057298 =300038log2230.057298

你可能感兴趣的:(STMT)