Why didn’t I get 2.27 seconds?? But instead 0.01 seconds

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question
Why didn’t I get 2.27 seconds?? But instead 0.01 seconds
def getInput(): #Defined the getInput function
h=int(input("Enter the initial height of the ball:")) #Prompts user to entera integer for the initial height of the bac
vaint (input("Enter the initial velocity of the bal1:"))#Prompts user to ente a integer for the initiol velocity of the
isvalid(h,v)#Called isValid() function with two arguments h and v
20
def isValid(h,v): #Defined the isValid function with two arguments Like h and v
if(h<=0): #Checks the condition. If height is <=0, the condition matches and the below Line is executed
print("Make sure your velocity and height is a positive number") #Disploys not a positive number if height and veloc
else: #Execute this block if the condition above doesn't match
height= maximumHeight(h, v) #Execute this Line if the condition doesn't match. Called maximumHeight function with two
print ("The maximum height of the ball is", height, "feet.") #Displayed and returns the value by maximumHeight function
time=approxTime (h, v)#CalLled approxTime with two parameters passing and stored the result which is returned by the app
print("The ball will hit the ground after approximately", time ,"seconds.") #Displays the returned value from the app
O def maximumHeight(h,v): #Defined maximumHeight function with two arguments which is passed through called functions
t=(v/32) #Divide velocity by 32 to get the time
maxHeight= h+(v*t)-(16*(t*t)) #calculates the maxHeight with the formulo
return maxHeight #return the value to the called function
E def approxTime (h, v): #Defined approxTime function with two arguments of h and v
t=0 #Initialize time with e
height=h+(v*t)-16* (t*t) #calculote height with the height formula ond stored in height
while height >=0: #Loop defined executes until condition is matched
t += 0.01 #added time (t) with time (t) and stored in time(t)
height=h+(v*t)-16* (t*t) #calculate height with the formula and stores the result in height. If height is >=0, Loop will
return t
getInput () #Colls the getInput() function
Program Quiz 2.py x
ized ***
***
Transcribed Image Text:def getInput(): #Defined the getInput function h=int(input("Enter the initial height of the ball:")) #Prompts user to entera integer for the initial height of the bac vaint (input("Enter the initial velocity of the bal1:"))#Prompts user to ente a integer for the initiol velocity of the isvalid(h,v)#Called isValid() function with two arguments h and v 20 def isValid(h,v): #Defined the isValid function with two arguments Like h and v if(h<=0): #Checks the condition. If height is <=0, the condition matches and the below Line is executed print("Make sure your velocity and height is a positive number") #Disploys not a positive number if height and veloc else: #Execute this block if the condition above doesn't match height= maximumHeight(h, v) #Execute this Line if the condition doesn't match. Called maximumHeight function with two print ("The maximum height of the ball is", height, "feet.") #Displayed and returns the value by maximumHeight function time=approxTime (h, v)#CalLled approxTime with two parameters passing and stored the result which is returned by the app print("The ball will hit the ground after approximately", time ,"seconds.") #Displays the returned value from the app O def maximumHeight(h,v): #Defined maximumHeight function with two arguments which is passed through called functions t=(v/32) #Divide velocity by 32 to get the time maxHeight= h+(v*t)-(16*(t*t)) #calculates the maxHeight with the formulo return maxHeight #return the value to the called function E def approxTime (h, v): #Defined approxTime function with two arguments of h and v t=0 #Initialize time with e height=h+(v*t)-16* (t*t) #calculote height with the height formula ond stored in height while height >=0: #Loop defined executes until condition is matched t += 0.01 #added time (t) with time (t) and stored in time(t) height=h+(v*t)-16* (t*t) #calculate height with the formula and stores the result in height. If height is >=0, Loop will return t getInput () #Colls the getInput() function Program Quiz 2.py x ized *** ***
Write a program to provide information on the height of a ball thrown
straight up into the air. The program should request as input the initial
height, h feet, and the initial velocity, v feet per second. The height of the
ball after t seconds is, in feet:
h+ vt – 161²
The program should perform the following two calculations:
1. Determine the maximum height of the ball. Note: The ball will reach its
maximum height after v/32 seconds.
2. Determine the approximately when the ball will hit the ground. Hint:
Calculate the height after every 0.01 second and determine when the
height is not longer a positive number.
A function named getlnput should be used to obtain the values of h and v
and that function should call a function named isValid to ensure that the
input values are positive numbers. Each of the tasks 1 and 2 should be
carried out by functions. Also within one of your function you must use
the return feature (you can use this feature in all functions if you want as
well). Below is example of the inputs and outputs that you could get:
Enter the initial height of the ball: 5
Enter the initial velocity of the ball: 34
The maximum height of the ball is 23.06 feet.
The ball will hit the ground after approximately 2.27 seconds.
Transcribed Image Text:Write a program to provide information on the height of a ball thrown straight up into the air. The program should request as input the initial height, h feet, and the initial velocity, v feet per second. The height of the ball after t seconds is, in feet: h+ vt – 161² The program should perform the following two calculations: 1. Determine the maximum height of the ball. Note: The ball will reach its maximum height after v/32 seconds. 2. Determine the approximately when the ball will hit the ground. Hint: Calculate the height after every 0.01 second and determine when the height is not longer a positive number. A function named getlnput should be used to obtain the values of h and v and that function should call a function named isValid to ensure that the input values are positive numbers. Each of the tasks 1 and 2 should be carried out by functions. Also within one of your function you must use the return feature (you can use this feature in all functions if you want as well). Below is example of the inputs and outputs that you could get: Enter the initial height of the ball: 5 Enter the initial velocity of the ball: 34 The maximum height of the ball is 23.06 feet. The ball will hit the ground after approximately 2.27 seconds.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Public key encryption
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,