hmwrk 5 - University of Colorado Introduction to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
University of Colorado Introduction to Engineering Computing – GEEN 1300 Spring 2008 Homework 5 Solutions Problem 2 on page 367 of Volume II of the textbook. Begin by re-reading section 3 of Chapter 12, especially pp 326-329, and reviewing slides 20-23 of Lecture 10. One key point in this solution is that Sub Switch thinks that its first argument is named e, its second argument is named b, and its third argument is named d. When you call Switch with some other variables – say Switch(x, y, z) – it “hooks” those variables that you called it with (x,y,z) to its own internal names (e,b,d). This acts as a pipeline out to those other variables: if you refer to e inside Switch, it'll reach out and access the variable x. This got confusing in this problem because the textbook authors had variables in different places with the same names. They did this in order to make you think very carefully about which variable gets accessed by each reference, but it created more confusion than thinking! Another key point in this problem is the control flow: Sub Calc calls Sub Switch, which means that the execution looks like this: That means that the four points in the problem where you're asked for the values of a, b, etc. come up in different order in the computer than they do on the textbook pages.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The first line of Calc (a = -1: and so on) happens before the branch to Switch. It sets the values of three of Switch’s internal variables (b, c, and d), leaves the other one (e) alone, and also sets the value of the “global” variable a. After this line of code is executed, the values of a, b, c, d, and e are -1, 2, 8, 4, 0. This is the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 3

hmwrk 5 - University of Colorado Introduction to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online