Answered step by step
Verified Expert Solution
Link Copied!

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 1
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 m/s2. The formula for calculating speed is s=at
s
=
a
t
where a is acceleration and t is time.
Function 2
Function Name: accelerationFromButton
Parameters
buttonForce : double
Return Type
double
Description
Takes a double between 0 and 10 representing how hard the user is pressing the acceleration button and converts it to an acceleration in m/s2. Use the formula a=f0.463
a
=
f
0.463
where f is the buttonForce and 0.463 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 0 and 10 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 0 until the time entered by the user in 3-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 3 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 3. The final value should not be duplicated.
To make sure your functions are compatible with the rest of the game, they will be unit-tested.
Input Validation:
You should ensure that the user input does not cause input failure. You should also ensure that the button force is between 0 and 10 and that the total time is greater than 0.
Sample Output:
Enter the button force between 0 and 10: 5
Enter the total acceleration time in seconds: 29
Acceleration is 2.315 m/s^2
Time in s Speed in m/s
******************************
00.000
36.945
613.890
920.835
1227.780
1534.725
1841.670
2148.615
2455.560
2762.505
2967.135
Enter the button force between 0 and 10: a
You entered something that is not a number. Please Try again.
Enter the button force between 0 and 10: 90
The button force needs to be between 0 and 10.
Enter the button force between 0 and 10: -10
The button force needs to be between 0 and 10.
Enter the button force between 0 and 10: a
You entered something that is not a number. Please Try again.
Enter the button force between 0 and 10: 3
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: -10
The total acceleration time must be greater than 0.
Enter the total acceleration time in seconds: 0
The total acceleration time must be greater than 0.
Enter the total acceleration time in seconds: 5
Acceleration is 1.389 m/s^2
Time in s Speed in m/s
******************************
00.000
34.167
56.945

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions