Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <sstream>
- using namespace std;
- int main()
- {
- float g=9.81;
- ifstream infile("/home/user/in.txt");
- string line;
- getline(infile,line);
- istringstream iny(line.c_str());
- float x ,y, vx, vy, dt;
- iny>>x>>y>>vx>>vy>>dt;
- infile.close();
- ofstream file;
- float eps = 0.0001;
- file.open("/home/user/out.txt");
- while (vx * vx + vy * vy > eps){
- x=x+vx*dt;
- y=y+vy*dt;
- file << x << " " << y << endl;
- vy-=g*dt;
- //cout << x << "\t" << y << "\t" << vx << "\t" << vy << endl;
- if (y<0){
- y=0;
- vy=vy*-1;
- vy=vy*0.5;
- vx=vx*0.5;
- }
- }
- file.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment