Advertisement
Serafim_

Файлы 2

Dec 15th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 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 outfile;
  18.     float eps = 0.001;
  19.     outfile.open("/home/user/out.txt");
  20.     while (vx * vx + vy * vy > eps){
  21.         x=x+vx*dt;
  22.         y=y+vy*dt;
  23.         outfile << 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*=-0.5;
  29.             vx*= 0.5;
  30.  
  31.  
  32.         }
  33.  
  34.         outfile<<x<<' '<<y<<endl;
  35.  
  36.     }
  37.  
  38.     outfile.close();
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement