Write a C++ program called onlineB.cpp to calculate horizontal range of the projectile motion (R) when a baseball player throws a ball at a speed of 30 ms-1 and the angle (in degrees) is given by the user. The given below is the equation to calculate the horizontal range of the projectile motion.
v = 30.0 (speed of the throwing), g = 9.8 (gravity), and θ = angle in radians
Sample Output
#include<bits/stdc++.h>
#define PI 3.14
#define g 9.8
#define v 30
using namespace std;
float convert_rad(float angle)
{
float rad;
rad=(angle*PI)/180;
return rad;
}
float range(float angle)
{
float R;
R=(pow(v,2)*sin(2*convert_rad(angle)))/g;
return R;
}
int main()
{
float angle;
cout<<"Velocity of projection = 30 m/s ";
cout<<"\nEnter the angle of projection in degrees ";
cin>>angle;
if(angle<=60 || angle>=45)
{
for(int i=angle;i>=35;i--)
{
cout<<"\nRange of projectile for angle = "<<i<<" is equal to "<<range(i);
}
}
else
{
cout<<"Projection angle out of range ";
}
}
Comments
Leave a comment