02 - C++ Basics, Programs, and Expressions

02 - C++ Basics, Programs, and Expressions - Engineering...

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

View Full Document Right Arrow Icon
Engineering 101 C++ Basics:  Programs and  Expressions
Background image of page 1

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

View Full DocumentRight Arrow Icon
Quote of the Day - Confucius The people may be made to follow a path of action but they may not be made to understand it.
Background image of page 2
How is data sent to/from the caller? n Pass-by-value  copies the data from the caller to a new  location in the algorithm. n When pass-by-value is used to send data back to the caller,  this is called a  return. n The caller has the option to ignore this kind of data. n Pass-by-reference  gives direct access to the data in  the caller’s environment. n The caller cannot ignore pass-by-reference data send to it  since the data was directly changed.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Consider the  Remainder  Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Caller Algorithm A x y Caller Algorithm A x y Call-by-value Call-by-reference 20 7 20 7 a b a b
Background image of page 4
Consider the  Remainder  Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Caller Algorithm A x y Caller Algorithm A 20 x y Call-by-value Call-by-reference 20 7 20 7 a b a b
Background image of page 5

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

View Full DocumentRight Arrow Icon
Consider the  Remainder  Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Caller Algorithm A x y Caller Algorithm A 20 7 x y Call-by-value Call-by-reference 20 7 20 7 a b a b
Background image of page 6
Consider the  Remainder  Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Caller Algorithm A x y Caller Algorithm A 13 7 x y Call-by-value Call-by-reference 13 7 20 7 a b a b
Background image of page 7

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

View Full DocumentRight Arrow Icon
Consider the  Remainder  Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Caller Algorithm A x y Caller Algorithm A 6 7 x y Call-by-value Call-by-reference 6 7 20 7 a b a b
Background image of page 8
Consider the  Remainder  Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Caller Algorithm A x y Caller Algorithm A 6 7 x y Call-by-value Call-by-reference 6 7 20 7 6 6 a b output a b output
Background image of page 9

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

View Full DocumentRight Arrow Icon
Caller Algorithm A x y Caller Algorithm A 6 7 x y Call-by-value Call-by-reference 6 7 20 7 6 6 a b a b Call-by-reference can cause changes in the caller aside from returning output explicitly. This output could be ignored. This output cannot be ignored.
Background image of page 10
What does the algorithm do? Mystery Algorithm n Request a value for  a n Request a value for  b n if  a ≥   then assign  to  c n if  then assign  to  c n while (remainder( a c )≠0 OR  remainder( b c ) ≠ 0) n      subtract one from  c n return  c n end remainder( x y ) 1. Request a value for  x 2. Request a value for  y 3. while  x ≥   do 4.      assign  x - y  to 
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 75

02 - C++ Basics, Programs, and Expressions - Engineering...

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

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