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

code in C 2. In function main declare coordinates for two points (xl, yl, x2, y2

ID: 3703979 • Letter: C

Question

code in C

2. In function main declare coordinates for two points (xl, yl, x2, y2) and slope m and y-intercept b. Call a function get2points to read in the two sets of coordinates. Return the values to fiunction main, pass by address. Call a second function slopeIntercept to calculate the values of slope m and intercept b for the form y-mx+b. Function slopeIntercept has six parameters, the four coordinate values and pointers to the slope and y-intercept. Call a function display Equation to print the final form of the equation. Enclose the call statements in a while or do... while loop so that additional coordinates can be converted to the slope intercept format if desired Test with coordinate pairs: (4,3) and (-2,1) (1,1) and (5,17.8)

Explanation / Answer

Solution:

code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

void get2points(float *pointx1, float *pointy1, float *pointx2, float *pointy2)
{
printf(" Enter point x1: ");
scanf("%f",&*pointx1);
printf("Enter point y1: ");
scanf("%f",&*pointy1);
printf("Enter point x2: ");
scanf("%f",&*pointx2);
printf("Enter point y2: ");
scanf("%f",&*pointy2);
}

void slopeIntercept(float *pointx1, float *pointy1, float *pointx2, float *pointy2,float *pointm, float*pointb)
{
*m = (*pointy2-*pointy1)/(*pointx2-*pointx1);

*b = (*pointy2 - *m*(*pointx2));
}

void displayEquation(float m, float b)
{
printf("Equation of line is y = %0.2fx + %0.2f ",m, b);
}

int main()
{
float pointx1, pointy1, pointx2, pointy2, m, b, again;
while(1)
{
get2points(&pointx1, &pointy1, &pointx2, &pointy2);
slopeIntercept(&pointx1, &pointy1, &pointx2, &pointy2, &pointm,&b);
displayEquation(m,b);

printf("Enter a postive number to input again, negative to exit: ");
scanf("%f",&again);

if(again < 0)
break;
}   

return 0;
}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)