kilolilo

graph

Dec 8th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <sstream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     float g=9.81;
  10.     ifstream infile("/home/user/in.txt");
  11.     string line;
  12.     getline(infile,line);
  13.     istringstream iny(line.c_str());
  14.     float x ,y, vx, vy, dt;
  15.     iny>>x>>y>>vx>>vy>>dt;
  16.     infile.close();
  17.     ofstream file;
  18.     float eps = 0.0001;
  19.     file.open("/home/user/out.txt");
  20.     while (vx * vx + vy * vy > eps){
  21.         x=x+vx*dt;
  22.         y=y+vy*dt;
  23.         file << x << "    " << y << endl;
  24.         vy-=g*dt;
  25.         //cout << x << "\t" << y << "\t" << vx << "\t" << vy << endl;
  26.         if (y<0){
  27.             y=0;
  28.             vy=vy*-1;
  29.             vy=vy*0.5;
  30.             vx=vx*0.5;
  31.         }
  32.     }
  33.     file.close();
  34.     return 0;
  35. }
Add Comment
Please, Sign In to add comment