DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Sara Guest

Can anyone do this?! I would be forever greatful!!

Write a function call ShotDistance that will calculate the distance a shot
went given the angle of elevation of the barrel of a cannon (in degrees)
and an initial velocity of the shell. The formula for the distance is Distance
= velocity ^2 * sin(2* angle)/32.2

Function ShotDistance(By Val A as single, ByVal V as single) as single

Pre condition; A is an angle measure in degrees. V is a velocity in feet
per second

Post condition: ShotDistance is the distance the shell will travel when fired
at the given parameters.

2. Larry Rebich Guest

http://www.test24hour.com/samples/me.../projsamp.html

Cheers,
Larry Rebich

No personal e-mail questions :-)

"Sara" <sara@hotmail.com> wrote in message news:3a2efdb8\$1@news.devx.com...
>
> Can anyone do this?! I would be forever greatful!!
>
> Write a function call ShotDistance that will calculate the distance a shot
> went given the angle of elevation of the barrel of a cannon (in degrees)
> and an initial velocity of the shell. The formula for the distance is

Distance
> = velocity ^2 * sin(2* angle)/32.2
>
> Function ShotDistance(By Val A as single, ByVal V as single) as single
>
> Pre condition; A is an angle measure in degrees. V is a velocity in feet
> per second
>
> Post condition: ShotDistance is the distance the shell will travel when

fired
> at the given parameters.
>

3. Björn Olofsson Guest

I must be missing something... You wrote the code yourself! Ie,
Function ShotDistance(ByVal A As Single, ByVal V As Single) As Single
ShotDistance = V ^ 2 * Sin(2 * A) / 32.2
End Function

???
/B

"Sara" <sara@hotmail.com> skrev i meddelandet
news:3a2efdb8\$1@news.devx.com...
>
> Can anyone do this?! I would be forever greatful!!
>
> Write a function call ShotDistance that will calculate the distance a shot
> went given the angle of elevation of the barrel of a cannon (in degrees)
> and an initial velocity of the shell. The formula for the distance is

Distance
> = velocity ^2 * sin(2* angle)/32.2
>
> Function ShotDistance(By Val A as single, ByVal V as single) as single
>
> Pre condition; A is an angle measure in degrees. V is a velocity in feet
> per second
>
> Post condition: ShotDistance is the distance the shell will travel when

fired
> at the given parameters.
>

4. Arthur Wood Guest

close:

Sin takes angles in Radians, Sara said degrees, so minor change:

Function ShotDistance(ByVal A As Single, ByVal V As Single) As Single
dim Angle as Single

Angle= A/(2*3.1415926) 'convert A degrees to radians

ShotDistance = V ^ 2 * Sin(2*Angle) / 32.2

End Function

"Björn Olofsson" <bjorn.olofsson@tietoenator.com> wrote:
>I must be missing something... You wrote the code yourself! Ie,
>Function ShotDistance(ByVal A As Single, ByVal V As Single) As Single
> ShotDistance = V ^ 2 * Sin(2 * A) / 32.2
>End Function
>
>???
>/B
>
>"Sara" <sara@hotmail.com> skrev i meddelandet
>news:3a2efdb8\$1@news.devx.com...
>>
>> Can anyone do this?! I would be forever greatful!!
>>
>> Write a function call ShotDistance that will calculate the distance a

shot
>> went given the angle of elevation of the barrel of a cannon (in degrees)
>> and an initial velocity of the shell. The formula for the distance is

>Distance
>> = velocity ^2 * sin(2* angle)/32.2
>>
>> Function ShotDistance(By Val A as single, ByVal V as single) as single
>>
>> Pre condition; A is an angle measure in degrees. V is a velocity in feet
>> per second
>>
>> Post condition: ShotDistance is the distance the shell will travel when

>fired
>> at the given parameters.
>>

>
>

5. Alex Guest

Sara,

I want to clarify some tiny details
The given formula for shot distance assumes that the heights of place where
bullet were fired and place where it landed are equal
In this case function should check if the initial direction was 'up' because
the direction of gravity force is always down (at least for this kind of
problems)

Function ShotDistance(ByVal A As Single, ByVal V As Single) As Single
Dim n
Dim Angle As Single, PI As Single

PI = 3.1415926

'check if the angle is in range 0 to 360 degrees
If A < 0 Then
n = 1 + Abs(A \ 360)
A = A + n * 360
End If
If A > 360 Then
n = Abs(A \ 360)
A = A - n * 360
End If
Select Case A
Case 0 To 180
Angle = A * PI / 180
ShotDistance = V ^ 2 * Sin(2 * Angle) / 32.2
Case Else
ShotDistance = 0
End Select
End Function

Alex

"Arthur Wood" <wooda@saic-trsc.com> wrote:
>
>close:
>
> Sin takes angles in Radians, Sara said degrees, so minor change:
>
>
>Function ShotDistance(ByVal A As Single, ByVal V As Single) As Single
> dim Angle as Single
>
> Angle= A/(2*3.1415926) 'convert A degrees to radians
>
> ShotDistance = V ^ 2 * Sin(2*Angle) / 32.2
>
>
>End Function
>
>
>
>"Björn Olofsson" <bjorn.olofsson@tietoenator.com> wrote:
>>I must be missing something... You wrote the code yourself! Ie,
>>Function ShotDistance(ByVal A As Single, ByVal V As Single) As Single
>> ShotDistance = V ^ 2 * Sin(2 * A) / 32.2
>>End Function
>>
>>???
>>/B
>>
>>"Sara" <sara@hotmail.com> skrev i meddelandet
>>news:3a2efdb8\$1@news.devx.com...
>>>
>>> Can anyone do this?! I would be forever greatful!!
>>>
>>> Write a function call ShotDistance that will calculate the distance a

>shot
>>> went given the angle of elevation of the barrel of a cannon (in degrees)
>>> and an initial velocity of the shell. The formula for the distance is

>>Distance
>>> = velocity ^2 * sin(2* angle)/32.2
>>>
>>> Function ShotDistance(By Val A as single, ByVal V as single) as single
>>>
>>> Pre condition; A is an angle measure in degrees. V is a velocity in feet
>>> per second
>>>
>>> Post condition: ShotDistance is the distance the shell will travel when

>>fired
>>> at the given parameters.
>>>

>>
>>

>

6. Phil Weber Guest

Sara: This sounds suspiciously like a class assignment. We discourage
discussion participants from doing others' homework, since that defeats the
very purpose of the assignment. In the future, however, if you post a
message to our vb.getting.started newsgroup detailing what efforts you've
made to complete the assignment and where you're stuck, I'm sure someone can
help you get "over the hump," as they say, while still allowing you to learn
from the experience. Thanks, and good luck!
---
Phil Weber

P.S. -- To all of you who did Sara's assignment for her: shame on you! ;-)

7. Arthur Wood Guest

Mea culpa

"Phil Weber" <pweber@devx.com> wrote:
>Sara: This sounds suspiciously like a class assignment. We discourage
>discussion participants from doing others' homework, since that defeats

the
>very purpose of the assignment. In the future, however, if you post a
>message to our vb.getting.started newsgroup detailing what efforts you've
>made to complete the assignment and where you're stuck, I'm sure someone

can
>help you get "over the hump," as they say, while still allowing you to learn
>from the experience. Thanks, and good luck!
>---
>Phil Weber
>
>P.S. -- To all of you who did Sara's assignment for her: shame on you! ;-)
>
>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise