Answer to Question #188125 in C++ for Tharindu Attanayak

Question #188125

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

  • User may insert an angle above or equal 45° and below 60° as the highest angle.
  • Then the program should calculate the horizontal range of the projectile motion (R) for each angle until the angle become 35°.
  • Consider the gravity (g) as a constant.
  • You are required to calculate the 𝜃 in radians by using the given formula (PI = 3.14286 which is a constant).
  • Use the necessary header files to do the calculation.

 Sample Output

 

1
Expert's answer
2021-05-04T05:27:50-0400
#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 ";
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS