This must be done in C. Lab 6 Due March 7th, 2017 at 11:59 PM Overview In this l
ID: 3811673 • Letter: T
Question
This must be done in C.
Lab 6 Due March 7th, 2017 at 11:59 PM Overview In this lab, you will write a program that computes the following physics motion equations: 1. v vo Vo zo) 3, v 2 a 4. ry where ro is the initial position, ry s the final position, vo is the initial velocity, v f s the final velocity, a is acceleration, and t is time. See the Example Execution section below for detailed examples. objectives Use pointers to pass by reference Translate mathematical equations to C expressions e More practice with the switch statement More practice with a user menu More practice with the math library Function Prototypes These are the function declarations you will need in this lab. Place these lines above your main function and below your include statements. You will write the function definition e. implementation) for each of these functions. Note that result is an output parameter, where you will place the result of the equation instead of directly returning a value. List of all function prototypes displays user menu, reads input, and validates input int user menu (void); Equation functions that are pass by reference void equation 1(float *result) calculate motion equation 1 void equation 2 (float result) calculate motion equation 2 void equation (float result) Calculate motion equation 3 void equation4(float *result); calculate motion equation 4 User input functions return a value from user float get position i nitial void) Prompts user for x0 float get position final (void) Prompts user for xfExplanation / Answer
Answer ->
--------------------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
int user_menu(void);
float get_velocity_initial(void);
float get_velocity_final();
float get_position_initial(void);
float get_position_final(void);
float get_acceleration(void);
float get_time(void);
void equation1(float *result);
void equation2(float *result);
void equation3(float *result);
void equation4(float *result);
int main()
{
int t;
float result;
do
{
t=user_menu();
if(t==1)
{
equation1(&result);
break;
}
else if(t==2)
{
equation2(&result);
break;
}
else if(t==3)
{
equation3(&result);
break;
}
else if(t==4)
{
equation4(&result);
break;
}
else if(t==5)
{
printf("QUIT");
break;
}
else
{
printf("Ivalid option Please try again ");
}
} while(1);
return 0;
}
int user_menu(void)
{
int n;
printf("choose a motion equation 1-4 or choose 5 to QUIT ");
scanf("%d",&n);
return n;
}
void equation1(float *result)
{
float vi , a,t,vf;
vi=get_velocity_initial();
a=get_acceleration();
t=get_time();
vf = vi + (a*t);
result=&vf;
printf("your result is =%f ",*result);
}
void equation2(float *result)
{
float vi ,xi,a,t,xf;
xi=get_position_initial();
vi= get_velocity_initial();
t=get_time();
a=get_acceleration();
xf= (xi+vi*t + (1/2)*a*t*t);
result=&xf;
printf("your result is =%f ",*result);
}
void equation3(float *result)
{
float vi ,xi,a,xf,vf;
vi=get_velocity_initial();
a=get_acceleration();
xf=get_position_final();
xi=get_position_initial();
vf = sqrt(vi*vi + 2*a*(xf-xi));
result=&vf;
printf("your result is =%f ",*result);
}
void equation4(float *result)
{
float vi ,xi,a,t,vf,xf;
xi=get_position_initial();
vf=get_velocity_final();
vi=get_velocity_initial();
t=get_time();
xf=(xi+ 1/2*(vf+vi)*t);
result=&xf;
printf("your result is =%f ",*result);
}
float get_velocity_initial(void)
{
float vi;
printf("Enter initial velocity ");
scanf("%f ",&vi);
return vi;
}
float get_velocity_final(void)
{
float vf;
printf("Enter final velocity ");
scanf("%f ",&vf);
return vf;
}
float get_position_initial(void)
{
float xi;
printf("Enter initial position ");
scanf("%f ",&xi);
return xi;
}
float get_position_final(void)
{
float xf;
printf("Enter final position ");
scanf("%f ",&xf);
return xf;
}
float get_acceleration(void)
{
float a;
printf("Enter acceleration ");
scanf("%f ",&a);
return a;
}
float get_time(void)
{
float t;
printf("Enter time ");
scanf("%f ",&t);
return t;
}
-------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT >
choose a motion equation 1-4 or choose 5 to QUIT 3
Enter initial velocity 4.6
Enter acceleration 2.5
Enter final position 3.5
Enter initial position 2.1
your result is = 5.306600
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.