Answer to Question #101943 in C++ for alex

Question #101943
1. Write a C program that does the following:a. Display a message to the user that this program calculates range (distance) and the assumptions (conditions) such as level ground, zero air resistance, etc.b. Ask the user to enter initial velocity (in m/s).c. Ask the user to enter launch angle (in degrees).d. Convert angle from degrees to radians. Be sure to include a comment with the source of the conversion factors used. (Note: Do not use wiki-type sources.)e. Calculate and display range using the formula provided above. NOTE: Use a <math.h> function in the calculation.f. Output the range or distance to 2 decimal places. Be sure to include the units after the value (m).
1
Expert's answer
2020-01-29T05:19:53-0500

#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;

 }

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