// Calculate a trajectory of a projectile // no air resistance #include #include #include #include using namespace std; int main() { const double pi=3.1415926; const double g = 9.81; double y0, v0, angle0, x, y, t, dt; double y2; ofstream out2disk; y0 = 0.0; v0 = 100.0; angle0 = 70.0; dt = 0.1; angle0 = angle0*pi/180.0; t = 0.0; x = 0.0; y = y0; out2disk.open ("table70.dat"); //open the file cout.setf(ios::fixed | ios::showpoint); cout.precision(5); // cout // out to the screen out2disk // write to the disk << setw(12) <<"t" << setw(12) <<"x" << setw(12) << "y" << endl << setw(12) << t << setw(12) << x << setw(12) << y << endl; while (y >= 0.0) { t = t + dt; x = v0*cos(angle0)*t; y = y0 + v0*sin(angle0)*t - g*t*t/2.0; // y2 = y0 + x*sin(angle0)/cos(angle0) - g*x*x/(2.0*pow(v0*cos(angle0),2)); // cout out2disk << setw(12) << t << setw(12) << x << setw(12) << y << endl; } system ("pause"); return 0; }