Professional Documents
Culture Documents
Lecture 10 - Programming Fundamentals
Lecture 10 - Programming Fundamentals
1
Lecture 10 Objectives
10.1 Introduction
10.2 Types of Errors
10.3 Hand Tracing a Program
10.4 Summary
Lecture 10 10.1 Introduction
Introduction
• Hand tracing of programs:
• As if you are the computer, executing a program:
• step through and ‘execute’ each statement,
• one-by-one record the contents of all variables after
statement execution,
• using a hand trace chart (table)
10.1 Introduction
10.2 Types of Errors
10.3 Hand Tracing a Program
10.4 Summary
Lecture 10 10.2 Types of Errors
Types of Errors
• Debugging:
• Can be used within IDE (more during lab)
• Hand tracing of programs using pen and paper
Lecture 10 Contents
10.1 Introduction
10.2 Types of Errors
10.3 Hand Tracing a Program
10.4 Summary
Lecture 10 10.3 Hand Tracing A Program
Example:
int main ()
{ num1 num2 num3 avg
float num1,num2,num3,avg;
avg=(num1+num2+num3)/3;
Example:
int main ()
{ num1 num2 num3 avg
float num1,num2,num3,avg;
? ? ? ?
cout<<"Enter the first number: \n"; 1.1 ? ? ?
cin>>num1;
1.1 2.2 ? ?
cout<<"Enter the second number: \n";
cin>>num2; 1.1 2.2 3.3 ?
avg=(num1+num2+num3)/3;
int main()
{
int x, y, z;
x =10; y = 17;
z = x + y;
y = y - x;
int main()
{
int x, y, z;
x =10; y = 17;
z = x + y;
y = y - x;
cout<<"n: “<<n;
cout<<"\nm: “<<m;
x=4;
y=x*2+10%3-1*x;
x*=y/m;
cout<<"\ny: “<<y;
cout"\nx: “<<x;
return 0;
}
Lecture 10 10.3 Hand Tracing A Program
n m x y
Solution 10.2:
int main()
{
int n, m, x, y;
m=10;
n=m*2/(m+2);
m%=n+2;
cout<<"n: “<<n;
cout<<"\nm: “<<m;
x=4;
y=x*2+10%3-1*x;
x*=y/m;
cout<<"\ny: “<<y;
cout<<"\nx: “<<x;
return 0;
}
Lecture 10 10.3 Hand Tracing A Program
n m x y
Solution 10.2:
? ? ? ?
int main() ? 10 ? ?
{
int n, m, x, y; 1 10 ? ?
m=10; 1 1 ? ?
n=m*2/(m+2);
m%=n+2; 1 1 4 ?
1 1 4 5
cout<<"n: “<<n;
cout<<"\nm: “<<m; 1 1 20 5
x=4;
y=x*2+10%3-1*x;
x*=y/m;
cout<<"\ny: “<<y;
cout<<"\nx: “<<x;
return 0;
}
Lecture 10 Contents
10.1 Introduction
10.2 Types of Errors
10.3 Hand Tracing a Program
10.4 Summary
Lecture 10 10.4 Summary