02 - C++ Basics, Programs, and Expressions - Full

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

Info icon This 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
Image of page 1

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

View Full Document Right 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.
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.
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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
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
Image of page 7

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

View Full Document Right 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
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
Image of page 9

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

View Full Document Right 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.
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    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.
Image of page 11

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern