#include <iostream>
using namespace std;
double yIntercept(double rise, double run, double xcoor, double ycoor);
int main()
{
int cont;
double pointArray11[1];
double pointArray21[1];
cout << "This program finds the slope and two variations of the equation of the line that passes through these two points."<<endl;
while(cont!=0)
{
cout << "Please enter the coordinates of the first point." << endl;
for(int coor = 0; coor<2; coor++)
{
double* coordinateSpace1 = new double;
cout << "Coordinate?";
cin >> *coordinateSpace1;
pointArray11[coor] = *coordinateSpace1;
delete coordinateSpace1;
}
cout << pointArray11[0]<<pointArray11[1]<<endl;
cout << "Please enter the coordinates of the second point." << endl;
for(int rooc = 0; rooc<2; rooc++)
{
double* coordinateSpace2 = new double;
cout << "Coordinate?";
cin >> *coordinateSpace2;
pointArray21[rooc] = *coordinateSpace2;
delete coordinateSpace2;
}
cout << pointArray21[0]<<pointArray21[1]<<endl;
cout << pointArray11[0]<<pointArray11[1]
<< pointArray21[0]<<pointArray21[1]<<endl;
[B]//pointArray11[0] changes to same value as pointArray21[1] during the cout statement above and for the rest of the program[/B]
double slope1 = pointArray21[1] - pointArray11[1];
double slope2 = pointArray21[0] - pointArray11[0];
cout << "The slope of the line is: " << slope1 <<"/" << slope2 << endl;
cout << "The equation for the line is: y-" << pointArray11[1] << "=" << slope1 << "/"<<slope2 << "(x-"<< pointArray11[0] <<")"<<endl;
cout << "The slope-intercept form of this equation is: y=" <<slope1<<"/"<<slope2<<"x+"<<yIntercept(slope1, slope2, pointArray11[0], pointArray11[1])<<endl;
cout << "Continue? Press zero to quit and any number to continue." <<endl;
cin >> cont;
}
return 0;
}
double yIntercept(double rise, double run, double xcoor, double ycoor)
{
double b = rise/run*(0-xcoor)+ycoor;
return b;
}