

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Programming & Problem Solving I; Subject: Computer Engr & Computer Sci; University: California State University - Long Beach; Term: Fall 2003;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Objective: Learn to hand trace C++ program execution. For each of the function calls in the following program, construct a table that shows the changes of every variable during the execution of the function, and determine the function’s return value. Finally, show the final output of the program. Do all these without using the computer. #include
int mystery3(int n) { assert(n >= 100000 && n <= 999999); int temp = n; n = temp%10; temp /= 10; n = 10n + temp%10; temp /= 10; n = 10n + temp%10; temp /= 10; n = 10n + temp%10; temp /= 10; n = 10n + temp%10; temp /= 10; n = 10n + temp%10; return n; } int mystery4(int n, int d) { assert(n >= d && d > 0); while (n > d) n = n - d; return n; } double mystery5(double x, int n) { assert(x > 0.0); double y = 1.0; if (n < 0) { x = 1.0/x; n = -n; } while (n > 0) { if (n%2 == 0) { x = xx; n = n/2; } else { y = y*x; --n; } } return y;