Lecture06 - Engineering 101 Lecture 06 Intro to Functions...

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

View Full Document Right Arrow Icon
Engineering 101 Engineering 101 Lecture 06 Lecture 06 Intro to Functions Intro to Functions Prof. Michael Falk University of Michigan, College of Engineering
Background image of page 1

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

View Full DocumentRight Arrow Icon
Announcements Announcements Project 1 Due Wednesday at 9pm
Background image of page 2
Mathematical Operators Mathematical Operators Operator Meaning Arity Placement Precedence sign change unary prefix 15 * multiplication binary infix 13 / real division binary infix 13 / integer division binary infix 13 % remainder binary infix 13 + addition binary infix 12 subtraction binary infix 12
Background image of page 3

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

View Full DocumentRight Arrow Icon
Other Kinds of Operators Other Kinds of Operators Not all operators perform mathematical operations >> and << send output to and get input from external streams (keyboards, screens). = sets the value of an identifier. Operator Meaning Arity Placement Precedence << insertion binary infix 11 >> extraction binary infix 11 = assignment binary infix 2
Background image of page 4
Your Weight on Mars Your Weight on Mars The Universal Law of Gravitation States The force on a body on earth is 2 R GmM F = mg F = R =radius M =planet mass m =your mass G =6.672x10 -11 N
Background image of page 5

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

View Full DocumentRight Arrow Icon
Your Weight on Mars Your Weight on Mars Your Weight is the force exerted on you The Universal Law of Gravitation States Your weight on earth is 2 R GmM W = mg W E = R =radius M =planet mass m =your mass G =6.672x10 -11 N
Background image of page 6
Your Weight on Mars Your Weight on Mars So the ratio of your weight on another planet to your weight on earth is So if I know the mass of the planet, M, and the radius of the planet, R, I can find the change in my weight. ( 29 2 12 2 2 10 8 . 6 R M gR GM W W s m E - 2 = =
Background image of page 7

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

View Full DocumentRight Arrow Icon
What do we want What do we want the program to do? the program to do? What is your weight on earth? 165 Weight on Mars is 62.5
Background image of page 8
Start with the scaffolding Start with the scaffolding #include <iostream> using namespace std; int main( ){ double marsmass = 6.4e-23; double marsrad = 3.4e6; double earthweight; double marsratio; cout << “What is your weight on earth?” << endl; cin >> earthweight; marsratio = 6.8e-12*marsmass/(marsrad*marsrad); cout << “Weight on mars is ” << marsratio*earthweight << endl; return 0; }
Background image of page 9

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

View Full DocumentRight Arrow Icon
Add the Obvious Expresssions Add the Obvious Expresssions #include <iostream> using namespace std; int main( ){ double marsmass = 6.4e-23; double marsrad = 3.4e6; double earthweight; double marsratio; cout << “What is your weight on earth?” << endl; cin >> earthweight; marsratio = 6.8e-12*marsmass/(marsrad*marsrad); cout << “Weight on mars is ” << marsratio*earthweight << endl; return 0; }
Background image of page 10
Make sure to add declarations Make sure to add declarations #include <iostream> using namespace std; int main( ){ double marsmass = 6.4e-23; double marsrad = 3.4e6; double earthweight; double marsratio; cout << “What is your weight on earth?” << endl; cin >> earthweight; marsratio = 6.8e-12*marsmass/(marsrad*marsrad); cout << “Weight on mars is ” << marsratio*earthweight << endl; return 0; }
Background image of page 11

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

View Full DocumentRight Arrow Icon
What is missing? What is missing? #include <iostream> using namespace std; int main( ){ double marsmass = 6.4e-23; double marsrad = 3.4e6; double earthweight; double marsratio; cout << “What is your weight on earth?” << endl; cin >> earthweight; marsratio = 6.8e-12*marsmass/(marsrad*marsrad); cout << “Weight on mars is ” << marsratio*earthweight << endl; return 0; }
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 50

Lecture06 - Engineering 101 Lecture 06 Intro to Functions...

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

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