C++ programing

profileCR777
hw-07a_cpp-manual-tracing.pdf

ECE-206 HW-07A Page 1 of 1

HW-07A: Manual Tracing

If the response to the prompt "Enter an integer number: " of the C++ program below is 998,

manually trace the program and write the outputs of the program. As tracing is part of learning

the language, you will not learn if you copy from your friend!

//comments start with //

#include <iostream> //Library header to use for cout

using namespace std ; //all names in C++ library declared here

int main() // Every C++ program consists a main function.

{

int i,j, num; //declare three integer variables i, j and num

//these are local variables

cout << "Enter an integer number: "; //prompt

cin >> num; //read num

for (i=num; i<num+5; i++)

{

j = i; //set j to i

cout << j / 1000 << " "; //output j/1000 and a space

j = j % 1000; //j set to the remainder of j/1000

cout << j / 100 << " "; //output j/100 and a space

j = j % 100; //j set to the remainder of j/100

cout << j / 10 << " "; //output j/10 and a space

j = j % 10; //j set to the remainder of j/10

cout << j << endl; //output j and linefeed

}

}

Work to do and document to submit:

Traces of the program execution in the following format:

i j num output to monitor currently displayed on monitor screen

998 998 998 0 0

998 998 998 9 09

. . . . . you complete the remaining lines