Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a code: Your program must declare three functions using function prototyp

ID: 3907628 • Letter: C

Question

Create a code:

Your program must declare three functions using function prototypes.
2. The first function should be called “PrintInstructions”
3. This function takes no arguments and returns an int value, which the caller can use to
determine if the user wishes to quit (entered ‘q’ or ‘Q’) the program or continue (any
other character). This will require an if/else decision in your main function.
4. The second function should be called “GetData”.
5. This function must use pointers to get the required inputs (time, velocity, and
acceleration) from the user and store the values in the caller’s local variables in main.
6. The third function is called “AccelerationDisplacement”.

7. This function will take parameters by value from the caller in main and calculate the
distance an object will travel given time, initial velocity and acceleration and return the
calculated value as a type double to the caller.
8. The function should perform the calculation of the formula given.
9. The final function is called PrintOutput.
10. This function is called with a value argument and prints the formatted output to the
user with the calculations as shown in the required outputs below. The program should
then end gracefully.

Formulas:

The formula to determine the distance travelled by an accelerating body is shown below. This is
a physics kinematics formula.

d = displacement (distance)

vi = initial velocity

t = time

a = accelerations

d = (vi • t) + (½ • a) • t^2

Function Prototypes:

int PrintInstructions()

void GetData(float* , float* , float* )

double AccelerationDisplacement(float vi, float t, float a)

void PrintOutput(double result, float vi, float t, float a)

Explanation / Answer

#include <iostream>
using namespace std;

// function prototypes
int PrintInstructions();
void GetData(float* , float* , float* );
double AccelerationDisplacement(float vi, float t, float a);
void PrintOutput(double result, float vi, float t, float a);

int main() {

float tm,velocity,acceleration,result;

while(PrintInstructions())
{
GetData(&tm,&velocity,&acceleration);
result = AccelerationDisplacement(velocity,tm,acceleration);
PrintOutput(result,velocity,tm,acceleration);

}

return 0;
}

int PrintInstructions()
{
char option;
cout<<" Enter q to quit or any other character to continue to calculate displacement : ";
cin>>option;
if(option == 'q' || option == 'Q')
return 0;
else
return 1;
}
void GetData(float* t , float* velocity , float* acceleration )
{
cout<<" Enter time : ";
cin>>*t;
cout<<" Enter velocity : ";
cin>>*velocity;
cout<<" Enter acceleration : ";
cin>>*acceleration;
}

double AccelerationDisplacement(float vi, float t, float a)
{
return (vi*t + 0.5*a*t*t); // compute displacement
}

void PrintOutput(double result, float vi, float t, float a)
{
//print values
cout<<" Initial velocity : "<<vi;
cout<<" Time : "<<t;
cout<<" Acceleration : "<<a;
cout<<" Displacement : "<<result;
}

Output:

Enter q to quit or any other character to continue to calculate displacement :c
Enter time : 5
Enter velocity : 6.7
Enter acceleration : 3.9
Initial velocity : 6.7
Time : 5
Acceleration : 3.9
Displacement : 82.25
Enter q to quit or any other character to continue to calculate displacement :q

Do ask if any doubt. Please upvote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote