Question

There is a 75 foot tall wall and the target is located 150 feet past it....

There is a 75 foot tall wall and the target is located 150 feet past it. The target is 50 feet wide - we will ignore the height of the target and assume that anything that lands within the area of its base would hit the target. The catapault always launches rocks at a 45 degree angle - to make life easy we will assume that they are launched from a height of 0 feet. Your program should read in a distance the catapault is from the wall (in feet) and an initial velocity for the rock it throws and report whether the shot: hits the wall, is too short, is too long, or hits the target. If the shot does not hit the wall, report how far it traveled in total. In particular, you will need the Parabolic Trajectory equation that gives a height for the rock after it travels x feet and the Range equation. Your program is reading in u (initial velocity). Use the value 32.17405 for g and 3.1419265359 for Pl.

#include
using namespace std;
int main()
{
   int testcase;
   cout<<"Enter no of testcase ";
   cin>>testcase;
   while(testcase--)
   {
    int distance,velocity;
    cout<<"Enter distance from wall: ";
    cin>>distance;
    cout<<"Enter velocity: ";
    cin>>velocity;
    double g=32.17405;
    double pi=3.1419265359;
    int dis_from_wall_to_target=distance+150;
    int dis_from_wall_with_target=distance+150+50;
     //d*(1-d*g/v*v)>height of wall then it cross the walll
    double height=distance*(1.0-((distance*g*1.0)/(velocity*velocity)));
    if(height>75)
    {
        //travel_distance=(v*v)/g when ball cross the wall then total travelled distance by ball
        double travel_distance=(velocity*velocity*1.0)/g;
        if(travel_distance         {
            cout<<"Too short!\n";
        }
        else if(travel_distance<=dis_from_wall_with_target)
        {
            cout<<"Hit!\n";
        }
        else
        {
            cout<<"Too far!\n";
        }
        cout<<"Rock traveled "<     }
    else
    {
        cout<<"Hits the wall!\n";
    }
   }
    return 0;
}

does the job without the variable pi! why do i need it ?

Please also provide with an alternative way of writing this code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/* Actuall Working*/

#include <iostream>

using namespace std;

int main()
{
int testcase;
cout<<"Enter no of testcase ";
cin>>testcase;
while(testcase--)
{
int distance,velocity;
cout<<"Enter distance from wall: ";
cin>>distance;
cout<<"Enter velocity: ";
cin>>velocity;
double g=32.17405;
double pi=3.1419265359;
int dis_from_wall_to_target=distance+150;
int dis_from_wall_with_target=distance+150+50;
//d*(1-d*g/v*v)>height of wall then it cross the walll
double height=distance*(1.0-((distance*g*1.0)/(velocity*velocity)));
if(height>75)
{
//travel_distance=(v*v)/g when ball cross the wall then total travelled distance by ball
double travel_distance=(velocity*velocity*1.0)/g;
if(travel_distance <0) {
cout<<"Too short!\n";
}
else if(travel_distance<=dis_from_wall_with_target)
{
cout<<"Hit!\n";
}
else
{
cout<<"Too far!\n";
}
cout<<"Rock traveled "<<endl; }
else
{
cout<<"Hits the wall!\n";
}
}
return 0;
}

/* Screenshot of above code*/

EXPLAINATION:

pie value is not required as per the calculation.

It's working fine, if we commented the pi value..

As see the below output

Add a comment
Know the answer?
Add Answer to:
There is a 75 foot tall wall and the target is located 150 feet past it....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Green Monster, as shown below, is a wall 37 feet high in left field at...

    The Green Monster, as shown below, is a wall 37 feet high in left field at Fenway Park in Boston. The wall is 310 feet from home plate down the third base line. If the batter hits the ball 4 feet above the ground, neglecting air resistance, determine the minimum speed that the bat must impart to the ball that is hit over the Green Monster. COVIDIE CVS. ELABOR The equations of motions for the baseball are x(t) = (u...

  • 5.15 PROGRAM: Functions - Upset Fowls (C++) (1) Correct the first FIXME by moving the intro...

    5.15 PROGRAM: Functions - Upset Fowls (C++) (1) Correct the first FIXME by moving the intro text to the function stub named PrintIntro and then calling the PrintIntro function in main. Development suggestion: Verify the program has the same behavior before continuing. (2) Correct the second FIXME by completing the function stub GetUsrInpt and then calling this function in main. Notice that the function GetUsrInpt will need to return two values: fowlAngle and fowlVel. (3) Correct the third FIXME by...

  • Suppose you want to throw a dart across a room at a wall-mounted target and hit...

    Suppose you want to throw a dart across a room at a wall-mounted target and hit the target exactly at its center point. We call this center point of the target its “bull’s-eye”. The bull’s-eye is a horizontal distance d from the dart’s point of release and a height habove the dart’s point of release. To hit the bull’s-eye, you have a choice of the speed v at which you throw the dart and a choice of the angle θ...

  • 1. Bull's-Eye Bonanza. (Allotted Time 45 minutes) Suppose you want to throw a dart across a...

    1. Bull's-Eye Bonanza. (Allotted Time 45 minutes) Suppose you want to throw a dart across a room at a wall-mounted target and hit the target exactly at its center point. We call this center point of the target its "bull's eye". The bull's-eye is a horizontal distance d from the dart's point of release and a height h above the dart's point of release. To hit the bul'seye, you have a choice of the speed s at which you throw...

  • CODE GIVEN % Create a program to plot the motion of the ping pong ball with...

    CODE GIVEN % Create a program to plot the motion of the ping pong ball with drag. % The program will take inputs for velocity in m/s and angle of launch. % note that with a high speed camera I estmated a launch speed for a ping % pong ball could be 30 m/s. vel=30; %m/s angle=60; % convert the degrees into radians so MATLAB likes it angle=angle*pi/180; % set initial values (time, distance, mass, gravity, drag) x(1)=0; % meters...

  • Solve exactly if possible. Express all decimals to 4 significant figures. 1) 2) 3) 4) 5)...

    Solve exactly if possible. Express all decimals to 4 significant figures. 1) 2) 3) 4) 5) 6) 7) What are Newton's Laws of motion? What is a "frame of reference"? What is a coordinate system? Express the point x-3, y-4 using polar coordinates. What is the SI unit for force? How is it defined using SI base units? What are the four fundamental forces in the universe? What is the approximate gravitational acceleration, g, near the Earth's surface? If this...

  • Write a MATLAB Graphical User Interface (GUI) to simulate and plot the projectile motion – the...

    Write a MATLAB Graphical User Interface (GUI) to simulate and plot the projectile motion – the motion of an object projected into the air at an angle. The object flies in the air until the projectile returns to the horizontal axis (x-axis), where y=0. This MATLAB program should allow the user to try to hit a 2-m diameter target on the x-axis (y=0) by varying conditions, including the lunch direction, the speed of the lunch, the projectile’s size, and the...

  • please help and answer all ASAP please thank you so much Question 49 (1 point) When...

    please help and answer all ASAP please thank you so much Question 49 (1 point) When light travelling in glass enters glass with a higher index of refraction, the wave will be: a) partially transmitted with a change in phase b) transmitted forming a standing wave pattern in air c) reflected so as to form a node at the junction d) totally reflected at the junction e) partially reflected without a change in phase Question 38 (1 point) The charge,...

  • This is my process, can you fix it for me? 0 Input: Output: Value: Under control...

    This is my process, can you fix it for me? 0 Input: Output: Value: Under control of main function Under control of main function The purpose of this assignment is to become familiar with the process of providing overloaded operators for a class. The Rational class from Labs 02, 03, and 05 will be modified to provide overloaded operators for performing arithmetic on Rational numbers an overloaded unary minus for negating a Rational number (previously implemented as the additive an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT