#include<bits/stdc++.h>
#define PI 3.14159265359
#define g 9.80
using namespace std;
int main()
{
cout<<"This program calculates range(disance) of a projectile.";
cout<<"\nFor calculation purposes the following assumptions have been made: ";
cout<<"\nThe ground is considered to be flat(level ground).\nAir resistance has been neglected.\n";
cout<<"\nEnter the initial velocity of projectile(in m/s): ";
float u, x,y;
cin>>u;
cout<<"\nEnter the launch angle of projectile(in degrees): ";
cin>>x;
y=(x*PI)/180; //angle in radians=(angle in degrees)*PI/180
cout<<"\nThe launch angle of projectile(in radians): "<<y<<" radian";
//range=u*u*sin(2*(launch angle))/(2*g)
//g=universal gravitational constant = 9.8 m/(s*s)
float range = pow(u, 2)*sin(2*y)/2*g;
int digits=log10(floor(range))+1;
cout<<"\nRange of the projectile is "<<setprecision(digits + 2)<<range<<" m.";
return 0;
}
Comments
Leave a comment