practical quiz 2.debuggingreport.txt
来自「CMU SSD3 课程完整答案(除EXAM)」· 文本 代码 · 共 101 行
TXT
101 行
---------------------------------------------------------------------------
Bug #1
Description of the bug:
The variable "enumberOfC" increases twice while the variable "numberOfG" is never read.
Lines of source code that contain the bug:
if (nucleotide == 'A') {
numberOfA++;
} else if (nucleotide == 'T') {
numberOfT++;
} else if (nucleotide == 'C') {
numberOfC++;
} else if (nucleotide == 'C') {
numberOfC++;
}
Lines of the fixed code:
if (nucleotide == 'A') {
numberOfA++;
} else if (nucleotide == 'T') {
numberOfT++;
} else if (nucleotide == 'C') {
numberOfC++;
} else if (nucleotide == 'G') {
numberOfG++;
}
---------------------------------------------------------------------------
Bug #2
Description of the bug:
The variables containing the number of nucleotides are overrided by local variables in the method "countNucleotides()".
Lines of source code that contain the bug:
int numberOfA = 0;
int numberOfT = 0;
int numberOfC = 0;
int numberOfG = 0;
Lines of the fixed code:
numberOfA = 0;
numberOfT = 0;
numberOfC = 0;
numberOfG = 0;
---------------------------------------------------------------------------
Bug #3
Description of the bug:
The condition of "if" statement should be "and" instead of "or".
Lines of source code that contain the bug:
if ((firstNucleotide == input) || (secondNucleotide == input)) {
return true;
}
Lines of the fixed code:
if ((firstNucleotide == input) && (secondNucleotide == input)) {
return true;
}
---------------------------------------------------------------------------
Bug #4
Description of the bug:
The condition of while-loop is incorrect, which makes the iteration exit earlier than expected for certain inputs.
Lines of source code that contain the bug:
while (index < sequence.length() - 1) {
// The body of the while-loop.
}
Lines of the fixed code:
while (index < sequence.length()) {
// The body of the while-loop.
}
---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?