Code:
int get_problem(void);
double get_pt_slope(double *m, double *x1, double *y1);
double get2_pt(double *x1,double *y1,double *x2,double *y2);
double slope_intcpt_from2_pt(double x1,double y1,double x2,double y2,double *m, double *intercept);
double intcpt_from_pt_slope(double m,double x1, double y1,double *intercept);
double display2_pt(double x1,double y1,double x2,double y2);
double display_pt_slope(double m,double x1,double y1);
double display_slope_intcpt(double m, double intercept);
int main()
{
int x;
x=get_problem();
if (x==1)
{
double x1,y1,x2,y2,intercept,m;
get2_pt(&x1,&y1,&x2,&y2);
slope_intcpt_from2_pt(x1,y1,x2,y2,&m,&intercept);
display2_pt(x1,y1,x2,y2);
display_slope_intcpt(m,intercept);
}
if (x==2)
{
double m,x1,y1,intercept;
get_pt_slope(&m,&x1,&y1);
intcpt_from_pt_slope(m,x1,y1,&intercept);
display_pt_slope(m,x1,y1);
display_slope_intcpt(m,intercept);
}
return (0);
}
int get_problem(void)
{
int x;
printf("Select the form that you would like to convert to slope-intercept form: \n 1) Two-point form (you know two points on the line) \n 2) Point =slope form (you know the line's slope and one point) \n =>");
scanf("%d",&x);
return(x);
}
double get_pt_slope(double *m, double *x1, double *y1)
{
printf("Enter the slope =>");
scanf("%lf",&*m);
printf("Enter the x-y coordinates of the point seperated by a space =>");
scanf("%lf%lf",&*x1,&*y1);
}
double get2_pt(double *x1,double *y1,double *x2,double *y2)
{
printf("Enter the x-y coordinates of the first point seperated by a space =>");
scanf("%lf%lf",&*x1,&*y1);
printf("Enter the x-y coordinates of the second point seperated by a space =>");
scanf("%lf%lf",&*x2,&*y2);
}
double slope_intcpt_from2_pt(double x1,double y1,double x2,double y2,double *m, double *intercept)
{
*m=(y2-y1)/(x2-x1);
*intercept=((*m*(-x1))+y1);
}
double intcpt_from_pt_slope(double m, double x1, double y1, double *intercept)
{
*intercept=(m*(-x1))+y1;
}
double display2_pt(double x1,double y1,double x2,double y2)
{
printf("Two Point Form \n ((%.2f-%.2f) \n m=-----------------\n (%2f-%2f))\n",y2,y1,x2,x1);
}
double display_pt_slope(double m,double x1,double y1)
{
printf("Point-Slope Form \n y-%.2f=%.2f(x-%.2f)\n",y1,m,x1);
}
double display_slope_intcpt(double m, double intercept)
{
printf("Slope-Intercept Form \n y=%.2fx+%.2f ",m,intercept);
}