// 计算下列代码片段的 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);
\(n_1\)represents the number of different operators in the program
\(n_2\)represents the number of different operands in the program
\(N_1\)represents the total number of operators in the program
\(N_2\)represents the number of operators in the program total number of operands
Operator | Number of Occurrences | Operand | Number of Occurrences | Operand | Number of Occurrences |
---|---|---|---|---|---|
\(if\) | 1 | month | 3 | 10 | 1 |
\(<\) | 1 | year | 5 | 4 | 1 |
\(+=\) | 1 | left | 1 | 6 | 1 |
\(--\) | 1 | day | 1 | 100 | 1 |
\(+\) | 5 | 3 | 1 | 400 | 1 |
\(*\) | 2 | 12 | 1 | 7 | 1 |
\(/\) | 4 | 1 | 1 | ||
\(\%\) | 1 | 26 | 1 | ||
\(n_1=8\) | \(N_1=16\) | \(n_2=14\) | \(N_2=20\) |
- Halstead program vocabulary length Program vocabulary: \(n=n_1+n_2=22\)
- Halstead program length or simple length Program length:\(N=N_1+N_2=36\)
- Prediction length of the program:\(N\)^\(=n_1log_2n_1+n_2log_2n_2=53.5823\)
- Program capacity Volume:\(V=Nlog_2(n)=160.54\)
- Program Level Level:\(L\)^=\((2/n_1) \times (n_2/N_2)=0.175\)
- Program Difficulty:\(D=1/L\)^\(=5.714\)
- Programming workload Effort:\(E=V \times D=V/L\)^=\(917.326\)
- Language level:\(L'=L\)^\(\times L\)^\(\times V=4.917\)
- Programming time (hours):\(T\)^=\(E/(S \times f)=917.326 / (60 \times 60 \times 18)=0.0141h\)
- Average Statement Size:\(N/Number of Statements=36/4=9\)
- The predicted value of the number of errors in the program:\(B=V/3000=Nlog_2(n)/3000=0.0535\)