Professional Documents
Culture Documents
Lecture 11 - Programming Fundamentals
Lecture 11 - Programming Fundamentals
Lecture 11 - Programming Fundamentals
1
Lecture 11 Objectives
11.1 Introduction
11.2 Hand Tracing Examples
11.3 Summary
Lecture 11 11.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)
11.1 Introduction
11.2 Hand Tracing Examples
11.3 Summary
Lecture 11 11.2 Hand Tracing Examples
Example 11.1:
#include <iostream>
using namespace std; A B C D
int main()
{
int A, B;
float C,D;
A = 2;
B = 5.0;
C = B / A;
D = (float) B/A;
cout<<"\nGiven a = 2, b = 5";
cout<<"\nc = "<<C;
cout<<"\nd = "<<D<<endl;
return 0;
}
Lecture 11 11.2 Hand Tracing Examples
#include <iostream>
using namespace std;
int main()
{
int Var1=5,Var2=3,Var3=5.5,Var4=3,C;
C=++Var1%Var2++; Var1 Var2 Var3 Var4 C
C=--Var1%Var2++;
C=Var3++%--Var4;
C=++Var3%Var4--;
return 0;
}
Lecture 11 11.2 Hand Tracing Examples
A=5;
B=7;
Temp=A;
A=B;
B=Temp;
return 0;
}
Lecture 11 11.2 Hand Tracing Examples
#include <iostream>
using namespace std; n sum digit
int main()
{
int n = 1729, sum = 0, digit;
while (n > 0)
{
digit = n % 10;
sum = sum + digit;
n = n / 10;
}
cout << sum << endl;
return 0;
}
Lecture 11 Contents
11.1 Introduction
11.2 Hand Tracing Examples
11.3 Summary
Lecture 11 11.3 Summary
14