Copyright © by Curt Hill

Slides:



Advertisements
Similar presentations
CS 240 Computer Programming 1
Advertisements

Chapter 15 Debugging. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Debugging with High Level Languages.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Which Language is Better?
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
Copyright Curt Hill A Quick Introduction to Looping Breadth not Depth.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
Copyright Curt Hill Arrays in C/C++ More on usage.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
Introduction to Programming Lecture 4. Key Words of C main main if if else else while while do do for for.
1 2/2/05CS250 Introduction to Computer Science II Pointers.
Copyright Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
Debugging and Printing George Mason University. Today’s topics Review of Chapter 3: Printing and Debugging Go over examples and questions debugging in.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
CS 240 Computer Programming 1
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
Copyright © 2016 Curt Hill Static Code Analysis What it is and does.
Bill Tucker Austin Community College COSC 1315
Basic concepts of C++ Presented by Prof. Satyajit De
The Second C++ Program Variables, Types, I/O Animation!
Static Code Analysis What it is and does. Copyright © 2016 Curt Hill.
CMPT 201.
Bill Tucker Austin Community College COSC 1315
Chapter 2 Assignment and Interactive Input
Chapter 1. Introduction to Computers and Programming
Barb Ericson Georgia Institute of Technology Dec 2009
C++ Arrays.
Static Methods 14-Nov-18.
Constructing and Using
Iteration with While You can say that again.
Repetition Statements
2008/10/27: Lecture 13 CMSC 104, Section 0101 John Y. Park
Introduction to C++ Programming
Chapter 5 Function Basics
Programming Funamental slides
Value returning Functions
Constants in Java Why and How Copyright © Curt Hill.
توكيد الذات.
Arrays in Java What, why and how Copyright Curt Hill.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Compound Statements A Quick Overview
Accomplishing Executables
How does the complexity of the flow of control affect test cases?
Tracing What, How, and Why Copyright © Curt Hill,
Observing how the machine acts
CISC181 Introduction to Computer Science Dr
Assignment Operators Topics Increment and Decrement Operators
Examining Variables on Flow Paths
The Java switch Statement
Fundamental Programming
Repetition Statements (Loops) - 2
Creating and Using Pointer Variables in C++ By: Ed Brunjes
Assignment Operators Topics Increment and Decrement Operators
Introduction to Programming
Assignment Operators Topics Increment and Decrement Operators
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Consider the following code:
The IF Revisited A few more things Copyright © Curt Hill.
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
Programming Fundamental-1
Methods Scope How are names handled?
Presentation transcript:

Copyright © 2004-2017 by Curt Hill Tracing What, How, and Why Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill What? Tracing is the simulation of a computer program or part of a computer program We “play computer” The results should be the same as if the program were executed on a real machine The simulation needs to cover every relevant aspect of the computation Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Elbonian Computers Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Why? Essential debugging tool Important learning technique A correct trace demonstrates that you understand the fundamentals We will have tracing exercises in class and on tests Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill How? Find the first statement to be executed Write down all the variables Used to record their current value As new variables are encountered they may be added to the list For each statement that is encountered: Determine its action Record changes to any variables Show the final values when execution is complete Copyright © 2004-2017 by Curt Hill

Consider the following code: #include <iostream.h> int main(){ int a,b=2,c=5; cin >> a; b = a*c c = b/2 – c + 2 cout << a << “ “ << b << “ “ << c; return 0; } Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Now what? What is the first executable statement? The declaration Record the variables and their value Then step through the statements Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill First step: #include <iostream.h> int main(){ int a,b=2,c=5; cin >> a; b = a*c c = b/2 – c + 2 cout << a << “ “ << b << “ “ << c; return 0; } a b c ? 2 5 Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Second step: #include <iostream.h> int main(){ int a,b=2,c=5; cin >> a; b = a*c c = b/2 – c + 2 cout << a << “ “ << b << “ “ << c; return 0; } a b c ? 2 5 7 2 5 Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Third step: #include <iostream.h> int main(){ int a,b=2,c=5; cin >> a; b = a*c; c = b/2 – c + 2; cout << a << “ “ << b << “ “ << c; return 0; } a b c ? 2 5 7 2 5 7 35 5 Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Fourth step: #include <iostream.h> int main(){ int a,b=2,c=5; cin >> a; b = a*c; c = b/2 – c + 2; cout << a << “ “ << b << “ “ << c; return 0; } a b c ? 2 5 7 2 5 7 35 5 7 35 14 Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Fifth step: #include <iostream.h> int main(){ int a,b=2,c=5; cin >> a; b = a*c; c = b/2 – c + 2; cout << a << “ “ << b << “ “ << c; return 0; } a b c ? 2 5 7 2 5 7 35 5 7 35 14 Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Sixth step: #include <iostream.h> int main(){ int a,b=2,c=5; cin >> a; b = a*c; c = b/2 – c + 2; cout << a << “ “ << b << “ “ << c; return 0; } a b c ? 2 5 7 2 5 7 35 5 7 35 14 Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Right and Wrong There is a right way and a wrong way to do tracing The right way is this The wrong way is to attempt to analyze this algebraically That approach does not allow for a change in variables Copyright © 2004-2017 by Curt Hill

Copyright © 2004-2017 by Curt Hill Conclusion Tracing is something that you see in every test and many quizzes and group assignments It is very useful to determine if you understand what is happening A very good debugging tool as well Copyright © 2004-2017 by Curt Hill