03 - Functions and Procedures - Full

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

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

Engineering 101 Functions and Procedures

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

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

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

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

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

View Full Document
What do we want  the program to do? What is your weight on earth? 165 Weight on Mars is 62.5
Start with the scaffolding #include <iostream> using namespace std; int main( ){ return 0; }

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

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

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

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

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

View Full Document
n …you wanted to add in your weight on Jupiter  too?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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