03 - Functions and Procedures - Full

03 - Functions and Procedures - Full - Engineering 101...

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

View Full Document Right Arrow Icon
Engineering 101 Functions and Procedures
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 Even when walking in the company of two  others, I am bound to be able to learn from them. The good points of the one I copy; the bad points of the other I correct in myself.
Background image of page 2
Announcements n Project 1 is due Friday at 9pm n Project 2 will be released shortly thereafter n If you are at all confused about how to save your  file for submission, see us in office hours ASAP. n We need to finish up last lecture…
Background image of page 3

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

View Full DocumentRight Arrow Icon
Your Weight on Mars  n Your Weight is the force exerted on you n The Universal Law of Gravitation States n Your weight on earth is R=rad ius M=planet mass m=your mass G=6.672x10- 2 R GmM W = mg W E =
Background image of page 4
Your Weight on Mars  n So the ratio of your weight on another planet to your weight on  earth is n 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 - × = =
Background image of page 5

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

View Full DocumentRight Arrow Icon
What do we want  the program to do? What is your weight on earth? 165 Weight on Mars is 62.5  
Background image of page 6
Start with the scaffolding #include <iostream> using namespace std; int main( ){ return 0; }
Background image of page 7

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

View Full DocumentRight Arrow Icon
Add the Obvious Expresssions #include <iostream> using namespace std; int main( ){ cout << “What is your weight on earth?” << endl; cin >> earthweight; cout << “Weight on mars is ” << marsratio*earthweight   << endl; return 0; }
Background image of page 8
Make sure to add declarations #include <iostream> using namespace std; int main( ){ double marsmass = 6.4e23; double marsrad = 3.4e6; double earthweight; double marsratio; cout << “What is your weight on earth?” << endl; cin >> earthweight; 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 in the equation #include <iostream> using namespace std; int main( ){ double marsmass = 6.4e23; 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
Add comments for the reader #include <iostream> // Program written by someone using namespace std; // This computes your weight int main( ){ // if you happen to be on Mars double marsmass = 6.4e23; // The mass of Mars double marsrad = 3.4e6; // The radius of Mars double earthweight; // The weight on Earth double marsratio; // Ratio of Mars to Earth cout << “What is your weight on earth?” << endl; cin >> earthweight; // compute the weight of the person on Mars 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
n …you wanted to add in your weight on Jupiter  too?
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 / 102

03 - Functions and Procedures - Full - Engineering 101...

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