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

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

Engineering 101 Engineering 101 Lecture 06 Lecture 06 Intro to Functions Intro to Functions Prof. Michael Falk University of Michigan, College of Engineering

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

View Full Document
Announcements Announcements Project 1 Due Wednesday at 9pm
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

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

View Full Document
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
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

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

View Full Document
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
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 = =

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

View Full Document
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
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; }

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

View Full Document
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; }
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; }

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

View Full Document
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; }
This is the end of the preview. Sign up to access the rest of the document.

## 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
Ask a homework question - tutors are online