Question

whats the answer and explanation?
Programming 2 16. Write a program that reads in a set of starting positions, velocities, and angles of a projectile. It then

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

#CODE IN PYTHON

Hi There,

I am providing the code in Python and pictures to explain the question!

> the python file and the text file should be in the same folder

> Below is the code in which explanation is provided with the help of comments

import math
def distance(s,v,a):
pos=s
vel=v
vel=v**2 # Eg 3*3=9
angle=a
angle=2*a*0.0174533
angle=math.sin(angle) # Eg sin(angle)
d=0
d=(vel*angle)/9.8 # Projectile distance R is being calculated and returned
return d


a=[]
f = open("projectiles.txt", "r") # File projectiles.txt is opened
for x in f: #File is read line by line Eg 0 3 30
a=[]
d=0
a=x.split() # Line elements are splitted and stored in the list a Eg a=['0','3','30']
d=distance(int(a[0]),int(a[1]),float(a[2])) # Distance function is called Eg d=distance(0,3,30)

# Printing the values
print("for starting position: "+a[0]+",m velocity: "+a[1]+",m/s and angle: "+a[2])
print("projectile hits a target distance "+str(d)+"m away from the point "+a[0]+"m")
print()

> Now the image of a text file named projectiles.txt is provided

> Code image is provided in reference to the second image

> Output of the code is provided in the reference to the third image


TEXT FILE:

Help projectiles.txt - Notepad File Edit Format View 0 3 30 0 3 45 1 4 30 2.4 45

PROGRAM:

import math def distance (s,v,a): pos=s vel=v vel=v**2 angle-a angle=2*a*0.0174533 angle-math.sin(angle) d=0 d=(vel*angle) /9

OUTPUT:

0.8660256281860526 for starting position: 0,m velocity: 3, m/s and angle: 30 projectile hits a target distance 0.795329658538

I hope it will help you! For any queries do reach out to me in the comment section!

-----------------------------------------------------------------------------------------------------------------------------------------------------------

# CODE IN JAVA

Hi There,

> Below I am providing the code in java too! as mentioned afterward.

CODE:

package extra;
import java.io.File;
import java.util.*;
import java.lang.Exception;
import java.lang.Math;


public class Extra {
public static double calculate(int v, int a)
{
double d;
double velocity=Math.pow(v,2);
double angle=2*a*0.0174533;
angle=Math.sin(angle);
d=(velocity*angle)/9.8; //Calculation of the distance
return d;
}
public static void main(String[] args) throws Exception
{
String token;
double x;
int a1,a2;
File file = new File("C:\\Users\\HP-PC\\Desktop\\projectiles.txt"); //file is opened
Scanner sc = new Scanner(file);
List<String> temps = new ArrayList<String>();
while (sc.hasNextLine())
{
token=sc.nextLine();
temps.add(token); //lines from text file are added to the arraylist
}
String[] tempsArray = temps.toArray(new String[0]); //Arraylist is converted to array

for (String s : tempsArray) {
System.out.println(s);
a1=Character.getNumericValue(s.charAt(2)); //Extracting velocity
a2=Integer.parseInt(s.substring(4,6)); //Extracting Angle
x=calculate(a1,a2); //Function called
System.out.print("Distance: ");
System.out.println(x);
}
}     
}

OOW - Start Page x Extra.java x Source History . QEEQT B package extra; 2 O import java.io.File; import java.util.*; import j

Start Page > Extra.java * Source History C -Q25ECT D O O 22 D String token; double x; int al, a2; File file = new File(C:\

OUTPUT:

Output - Extra (run) x run: 0 3 30 Distance: 0.7953296585382115 0 3 45 Distance: 0.9183673469385674 1 4 30 Distance: 1.413919

Hope that it will help you!

Add a comment
Know the answer?
Add Answer to:
whats the answer and explanation? Programming 2 16. Write a program that reads in a set...
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
  • These questions are to be answered using MATLAB. I only need #3 answered, but #1 provides...

    These questions are to be answered using MATLAB. I only need #3 answered, but #1 provides information (like initial velocity, etc.) required for the questions. I think I have it done, but I'd like to see if there are other ways to use MATLAB for this question. PROJECTILES The distance a projectile travels when fired at an angle 8 is a function of time and can be divided into horizontal and vertical distances. Horizontal (1) = 1.V.cos(0) Vertical(t) = 1•...

  • 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...

  • I can't figure out how to change my code to write info in from a text...

    I can't figure out how to change my code to write info in from a text file for the input. I'll post the context of the problem I am working on and the code I have finished so far. The program will create a Catapult object that will create a searchable matrix of trajectories for the given speeds and angles. The object should store these values in a 2D array. Given a target range of minimum and maximum distances, representing...

  • Projectile A is fired at a speed Vo at an angle 0 above horizontal as shown...

    Projectile A is fired at a speed Vo at an angle 0 above horizontal as shown and projectile B is fired at the sar but at a speed of 2%. Use this for Questions #1-7. angle Draw the initial velocity vectors for both projectile A and projectile B. Remember that the length of your arrows is important. 1. 2. Compare the initial horizorntal and vertical velocities of projectiles A and B. Be specific. Explain your answers. 3. Compare the horizontal...

  • HW#5 Functions and Arrays For HW#5 we will return to the state method of solving the...

    HW#5 Functions and Arrays For HW#5 we will return to the state method of solving the ballistic projectile problem with added twists. The goal will be to hit a target 1000 meters east of your cannon but the wind is blowing from the south. Your initial muzzle velocity is fixed at 110 meters per second, but you can control the elevation and azimuth angles of your aim. Elevation angle is measured up or down. Azimuth angle is measured right or...

  • 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...

  • 5:16 lLTE ) Done 1 of 5 Assessment #1 (Kinematics of a Particle) Rectilinear Motion (Straight...

    5:16 lLTE ) Done 1 of 5 Assessment #1 (Kinematics of a Particle) Rectilinear Motion (Straight linc Motion 3. The position of a point during the interval of time from r otor 6 is given by ** * m. (a) What is the maximum velocity during this interval of time, and at what time does it occur? (b) What is the acceleration when the velocity is a maximum? (20 m/s, 0 m/s 3. A test projectile is fired horizontally into...

  • please answer all I beg you ASAP! and please try solving most of them thabk you...

    please answer all I beg you ASAP! and please try solving most of them thabk you so much Question 23 (1 point) At an instant a traffic light turns green, a truck starts with a constant acceleration of 1.8 m/s2. At the same moment a taxi travelling with a constant speed of 8.5 m/s overtakes and passes the truck. Which two equations properly describe the position of the truck and the taxi? a) dtruck = 8.5at dtaxi = 8.5at b)...

  • Please, I need help answering questions 10, 11, 12, 13, 14, and 15. Use the other...

    Please, I need help answering questions 10, 11, 12, 13, 14, and 15. Use the other pages as information to solve the questions. Use the questions below to keep track of key concepts from this lesson's study activity. YOUR ASSIGNMENT: Splatapults Away! The engineering club has built a catapult and wants to test it out. The local supermarket has donated some overripe fruits and vegetables, and now the club is holding a Splatapult challenge to see who can hit the...

  • The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use...

    The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...

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