ulvis.paste.net

Paste Search Dynamic
Recent pastes
Distance
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. /* KINEMATIC EQUATIONS
  8.  *
  9.  * yf= yi+vi*t-0.5*a*(t*t)
  10.  * vf= vi-at
  11.  *
  12.  * vf= sqrt((vi*vi)-2*gravity*(yf-yi))
  13.  *
  14.  */
  15.  
  16.  
  17. const double gravity = 9.8;   //unit: m/s^2
  18.  
  19. double computeDistance(double yi, double vi, double t);
  20. double maxDistance(double yi, double vi, double t);
  21.  
  22. int main() {
  23.  
  24.     double  yi, yf, vi, vf, t;
  25.     double ymax,tmax;
  26.  
  27.     cout<<"Can you please enter initial velocity in m/s?  ";
  28.     cin>>vi;
  29.     cout<<"Can you please enter initial height in meters?  ";
  30.     cin>>yi;
  31.  
  32.     cout<<"\ntime    displacement\n";
  33.  
  34.     yf=yi+vi*t-0.5*gravity*(t*t);
  35.     for (t=0.0; yf>=0.0; t+=0.1) {
  36.  
  37.         yf=yi+vi*t-0.5*gravity*(t*t);
  38.  
  39.         if (yf != abs(yf)) {
  40.             break;
  41.         }
  42.  
  43.         cout<<fixed<<showpoint<<setprecision(1)<<t<<setw(9)<<setprecision(2)<<yf<<endl;
  44.  
  45.         vf=vi-gravity*t;
  46.  
  47.         if (vf>=-0.5 && vf<=0.5) {
  48.             tmax=t;
  49.             ymax=yf;
  50.         }
  51.  
  52.     }
  53.  
  54.     if(t>0) {
  55.         t-=0.1;
  56.     }
  57.  
  58.     cout<<endl<<"IMPACT OCCURED AFTER "<<t<<endl;
  59.     cout<<"Max height was at " <<tmax<< " seconds with a height of " <<ymax<<" meters.";
  60.  
  61.  
  62.     return 0;
  63. }
Parsed in 0.010 seconds