Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are working on the newest racing game. Your part is to calculate the speed the car is moving based on acceleration and time. The
You are working on the newest racing game. Your part is to calculate the speed the car is moving based on acceleration and time. The game determines the acceleration based on how hard the user is pressing the analog trigger button or racing pedal. While the rest of the game is being written, you will write the functions that meet the specifications below.
Function
Function Name
speedDueToAcceleration
Parameters
acceleration : double
time : int
Return Type
double
Description
Takes an acceleration and time value and returns the speed. The time is given in seconds and the acceleration is given in ms The formula for calculating speed is sat
s
a
t
where a is acceleration and t is time.
Function
Function Name: accelerationFromButton
Parameters
buttonForce : double
Return Type
double
Description
Takes a double between and representing how hard the user is pressing the acceleration button and converts it to an acceleration in ms Use the formula af
a
f
where f is the buttonForce and is the force to acceleration conversion constant.
Until your functions can be incorporated into the rest of the game, you will need to create a main that prompt for the button force between and and the total time in seconds. You will write a program C that converts the button force to acceleration and then loop starting at time until the time entered by the user in second increments. Print a table that shows the speed the vehicle will be traveling at each iteration of the loopformat the speed and acceleration numbers to decimal places. Ensure the time entered by the user is the final value shown in the table, even if the total time is not divisible by The final value should not be duplicated.
To make sure your functions are compatible with the rest of the game, they will be unittested.
Input Validation:
You should ensure that the user input does not cause input failure. You should also ensure that the button force is between and and that the total time is greater than
Sample Output:
Enter the button force between and :
Enter the total acceleration time in seconds:
Acceleration is ms
Time in s Speed in ms
Enter the button force between and : a
You entered something that is not a number. Please Try again.
Enter the button force between and :
The button force needs to be between and
Enter the button force between and :
The button force needs to be between and
Enter the button force between and : a
You entered something that is not a number. Please Try again.
Enter the button force between and :
Enter the total acceleration time in seconds: a
You entered something that is not a number. Please Try again.
Enter the total acceleration time in seconds:
The total acceleration time must be greater than
Enter the total acceleration time in seconds:
The total acceleration time must be greater than
Enter the total acceleration time in seconds:
Acceleration is ms
Time in s Speed in ms
Step 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