general computer science for engineers cisc 106 lecture 21 dr. john cavazos computer and information...
Post on 19-Dec-2015
213 views
TRANSCRIPT
![Page 1: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/1.jpg)
General Computer General Computer Science Science
for Engineersfor EngineersCISC 106CISC 106
Lecture 21Lecture 21
Dr. John CavazosComputer and Information Sciences
04/10/2009
![Page 2: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/2.jpg)
Lecture OverviewLecture OverviewCommon ErrorsDebugging Tips (pgs 72 – 76)Symbolic Debugger (137-140)
![Page 3: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/3.jpg)
Different Kinds of ErrorsDifferent Kinds of ErrorsSyntax Errors x = (y + 3) / 2);
Run-time Errors x = n / 0;
Logical ErrorsRuns correctly but wrong
answer!
![Page 4: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/4.jpg)
Common ProblemsCommon ProblemsNot initializing all variablesStarting array index variable at 0Incorrect evaluation order in
equationOff by one errorInfinite loop
![Page 5: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/5.jpg)
Some easy fixesSome easy fixesBreak up equation into smaller
piecesAdd parenthesis to make
equation clearInitialize all variables!
![Page 6: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/6.jpg)
DebuggingDebuggingAdd print statements!Display value of all variablesRun through a very simple test
caseIncreasingly make test case
longerFor example, sorting an arraytry an empty array, try with one
element,try an array of size 2, then size 5,
so on…
![Page 7: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/7.jpg)
Finding an number in array
- Pass into function array and number
- Initialize array index to 1- Initialize number found boolean
variable- while number not found- if current array position has
num- set number found - end- If number found report!
![Page 8: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/8.jpg)
Finding a number in an array
function found = findNumber(array, value)
x = 1;found = false;while (found == false) if (a(x) == value) found = true; end end
What is the problem?
![Page 9: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/9.jpg)
Add some print statementsfunction found = findNumber(array,
value) x = 1;found = false;while (found == false) if (a(x) == value) found = true; end found xend
Note x does not change!
![Page 10: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/10.jpg)
Add some print statementsfunction found = findNumber(array,
value) x = 1;found = false;while (found == false) if (a(x) == value) found = true; end x = x + 1;end
Problem if value not found! Should test for this.
![Page 11: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/11.jpg)
Add some print statementsfunction found = findNumber(array,
value) x = 1;found = false;while (found == false && x <=
length(a)) if (a(x) == value) found = true; end x = x + 1;end
![Page 12: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/12.jpg)
Symbolic DebuggerSymbolic DebuggerOpen m-file to debug in Matlab
editorCan set breakpoints
Where you want execution to suspend
Execute in command window as normal
, 2009 from 1:00 PM to 1:30 PM
![Page 13: General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009](https://reader034.vdocument.in/reader034/viewer/2022050714/56649d365503460f94a0da0b/html5/thumbnails/13.jpg)
Symbolic DebuggerSymbolic DebuggerExecution suspends in editor at
breakpointCan view variables in command
windowCan step through the codeCan continue to next
breakpoint17, 2009 from 1:00 PM to 1:30 PM