Where d is the distance traveled by the ball in meters. a is the angle from the
ID: 3623063 • Letter: W
Question
Where
d is the distance traveled by the ball in meters.
a is the angle from the ground the cannon is pointed.
v is the intial velocity of the ball leaving the cannon in m/s.
g is the gravitational constant of 9.81 m/s/s.
t is the time the ball is in the air in seconds.
h is the maximum height the ball reaches in meters.
This assignment will test your knowledge of: writing formatted results to an external file, using cmath functions in assignment statements, using external void and single result functions, using a loop (you can choose which kind to use), and using an if else block; This will cover material up to and including Chapter 2.10.NOTE: Do not use a function called distance. distance is a reserved word in the std namespace.
Write a C++ program named xxxxpa2.cpp that does the following:
a. Asks the user for the distance of a target.
b. Asks the user for an angle from the horizontal that the cannon is aimed and fired.
c. Calls a void function that calculates the distance traveled, the maximum height reached, and the time traveled of the cannon ball for initial velocities of 10, 20, 30, and 40 m/s. Each of the three values (d, h, t) must be calculated using three separate single result functions.
d. Also in the void function the program checks to see if the cannon ball is within 1 meter of the target.
e. Repeats b. c. and d. for a total of 3 angles input by the user, without ending the program.
f. The void function also prints out three tables, one for each angle of the cannon to the screen and to a file named report.txt.
g. Each table should have the following format: The table heading lists the angle and other text to identify the table columns:
Column one is the initial velocity in m/s.
Column two is the maximum height reached in meters.
Column three is the time traveled in seconds
Column four is the final distance in meters.
Column five says HIT if the ball is within 1 meter of the target and MISS if it is not.
Each table will have 4 rows (not counting the heading), one for each value of initial velocity.
Give two digits to the right of the decimal point for all outputted results.
Your output to the screen should look like this:
Explanation / Answer
please rate - thanks
the numbers are slighly different because you didn't specify what to use for PI
#include <cmath>
#include <iostream>
#include <iomanip>
#define g 9.81
#define PI 22./7.
using namespace std;
void traveled(double,double,double&,double&,double&);
double dist(double,double);
double height(double);
double time(double,double,double);
int main()
{double target,angle,vzero,ht,t,d;
cout<<"Input the target distance in meters ";
cin>>target;
cout<<setprecision(2)<<fixed<<showpoint;
for(int i=0;i<3;i++)
{cout<<"Enter an angle from the horizon between 0 and 90 degrees ";
cin>>angle;
cout<<" vzero(n/s) height(n) time(s) distance(n) hit? ";
for(vzero=10;vzero<=40;vzero+=10)
{traveled(vzero,angle,ht,t,d);
cout<<right<<setw(8)<<vzero<<setw(15)<<ht<<setw(12)<<t<<setw(16)<<d<<" "
<<setw(4)<<left;
if(d<=target+1&&d>=target-1)
cout<<"HIT ";
else
cout<<"MISS ";
}
}
system("pause");
return 0;
}
void traveled(double v,double a,double& h,double& t,double& d)
{a=a*PI/180.; //convert to radians
d=dist(v,a);
t=time(d,v,a);
h=height(t);
}
double dist(double v,double a)
{return v*v*sin(2*a)/g;
}
double height(double t)
{return (g*pow(t/2.,2))/2.;
}
double time(double d ,double v,double a)
{return d/(v*cos(a));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.