Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ Question 2(5pt): Braking Distance Displacement, D (i.e. a distance) for a braking vehicle can be calculated with the initial velocity, I, the final velocity,
C++
Question 2(5pt): Braking Distance Displacement, D (i.e. a distance) for a braking vehicle can be calculated with the initial velocity, I, the final velocity, F, and deceleration, a. (F2 - 12) (-2.0) =D Write a function called displacement that takes as parameters: initial velocity, I, final velocity F, and deceleration a. Function specifications: Your function must be named displacement Your function takes three parameters (all double, in this order) o Initial velocity I o Final velocity F Deceleration a Your function should return the appropriate displacement, D, of the vehicle as double. If one or more values are invalid, the function print all the error messages in this order and return 0. If your function receives negative velocities then it must print "Velocity should be greater than zero." If your function receives a zero deceleration then it must print "No brakes were applied." If your function receives a negative deceleration then it must print "The vehicle is speeding up." If your function receives F > I then it must print Error in acceleration values." For example: Bob is riding his bicycle to the store at a velocity of 4 m/s, when an aardvark runs out in front of him. He quickly brakes to a complete stop, with a deceleration of 2 m/s. What is his displacement? Note that because Bob is stopped, the final velocity, F = 0. His initial velocity, I = 4 m/s. The deceleration is 2 m/s. Therefore the function should return 4. (02 42) (-2-2) = 4 Sample run 1 (bold is user input) Enter initial velocity: 10 Enter final velocity: 1 Enter deceleration: 5 Displacement is 9.9 Sample run 2 (bold is user input) Enter initial velocity: 1 Enter final velocity: 2 Enter deceleration: 0 No brakes were applied. Error in acceleration valuesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started