1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double SlopeInt_from_PtSlope(double xcordinate, double ycordinate, double slopeLine){
double b = 0.0;
b = (ycordinate)-(slopeLine * xcordinate);
return b;
}
double SlopeInt_from_2Pt(double* m, double* b, double xcordinate, double ycordinate, double xcordinate2, double ycordinate2){
*m = (ycordinate2 - ycordinate) / (xcordinate2 - xcordinate);
*b = (ycordinate)-((*m) * xcordinate);
return;
}
int get_choice(int choice){
double xcordinate = 0.0;
double ycordinate = 0.0;
double xcordinate2 = 0.0;
double ycordinate2 = 0.0;
double slopeLine = 0.0;
double b = 0.0;
if (choice == 1){
printf("Enter the first x-y coordinate, x and y separated by a space: ");
scanf("%lf %lf", &xcordinate, &ycordinate);
printf("Enter the second x-y coordinate, x and y separated by a space: ");
scanf("%lf %lf", &xcordinate2, &ycordinate2);
printf("Two - point form\n");
Display_2Pt(xcordinate, ycordinate, xcordinate2, ycordinate2);
Display_SlopeInt(SlopeInt_from_2Pt(&slopeLine, &b, xcordinate, ycordinate, xcordinate2, ycordinate2), SlopeInt_from_2Pt(&slopeLine, &b, xcordinate, ycordinate, xcordinate2, ycordinate2));
}
if (choice == 2){
printf("Enter the slope: ");
scanf("%lf", &slopeLine);
printf("Enter the x-y coordinate, x and y separated by a space: ");
scanf("%lf %lf", &xcordinate, &ycordinate);
Display_PtSlope(xcordinate, ycordinate, slopeLine);
Display_SlopeInt(slopeLine, ((SlopeInt_from_PtSlope(xcordinate, ycordinate, slopeLine))));
}
return;
}
void Display_2Pt(double xcordinate, double ycordinate, double xcordinate2, double ycordinate2){
printf("\t(%lf - %lf\n", ycordinate2, ycordinate);
printf("m = -----\n");
printf("\t(%lf - %lf\n", xcordinate2, xcordinate);
}
void Display_PtSlope(double xcordinate, double ycordinate, double slopeLine){
printf("y - %lf = %lf(x - %lf)\n", ycordinate, slopeLine, xcordinate);
}
void Display_SlopeInt(double slope, double yintercept){
printf("y = %lfx + %lf\n", slope, yintercept);
}
int main(void){
int choice;
double xcordinate = 0.0;
double ycordinate = 0.0;
double xcordinate2 = 0.0;
double ycordinate2 = 0.0;
double slopeLine = 0.0;
double b = 0.0;
printf("-------------------------------------------------------------------------\n");
printf("Mode\t\t\tEquation\t\tGiven\n");
printf("-------------------------------------------------------------------------\n");
printf("Two-point form\t\tm=(y1-y1)/(x2-x1)\t(x1,y1),(x2,y2)\n");
printf("\nPoint-slope form\ty-y1 = m(x-x1)\t\tm, (x1,y1)\n");
printf("\nSlope-intercept form\ty = mx+b\t\tm, b\n");
printf("\nSelect the form that you would like to convert to Slope-intercept form:\n");
printf("1\tTwo-point form (you know two points on the line)\n");
printf("2\tPoint-slope form (you know the line's slope and one point)\n");
do{
printf("Enter your choice (1 or 2):");
scanf("%d", &choice);
} while ((choice != 1) && (choice != 2));
get_choice(choice);
return 0;
}
|