This preview shows pages 1–13. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Engineering 101 Functions and Procedures 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… 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 × = = 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; } 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; } 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.8e12*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.8e12*marsmass/(marsrad*marsrad); cout << “Weight on mars is ” << marsratio*earthweight << endl; return 0; } What if… n …you wanted to add in your weight on Jupiter too? #include <iostream>...
View
Full
Document
This note was uploaded on 01/30/2012 for the course ENGR 101 taught by Professor Ringenberg during the Winter '07 term at University of Michigan.
 Winter '07
 Ringenberg

Click to edit the document details