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

2. The table below summarizes three commonly used mathematical models of nonvert

ID: 3641773 • Letter: 2

Question

2. The table below summarizes three commonly used mathematical models
of nonvertical straight lines.
Mode Equation Given

Two-point form                   Y2 – Y1                   (X1 Y1), (x2,y2).
                                m   =
                                          X2 – X1

Point-slope form        Y – Y1 = m(x – X1)             m, (X1, y1)

Slope-intercept form   y=mx+b                           m,b


Design and implement a program that permits the user to convert either
two-point form or point-slope form into slope-intercept form. Your pro-
gram should interact with the user as follows:

Select the form that you would like to convert to slope-
intercept form:
1) Two-point form (you know two points on the line)

2) Point-slope form (you know the line's slope and one point)
=> 2

Enter the slope=> 4.2
Enter the x-y coordinates of the point separated by a space
=> 1 1
Point-slope form
y - 1.00 = 4.20(x - 1. 00)


Slope-intercept form
y = 4.20x - 3.20


Do another conversion (Y or N) => Y


Select the form that you would like to convert to slope-
intercept form:
1) Two-point form (you know two points on the line)
2) Point-slope form (you know the line's slope and one
point)
=> 1


Enter the x-y coordinates of the first point separated by a
space=> 4 3

Enter the x-y coordinates of the second point separated by a
space=> -2 1


Two-point form
         (1.00 - 3.00)
m=
         (-2.00 - 4.00)

Slope-intercept form
y=0.33x+1.66


Do another conversion (Y or N)=> N


Implement the following functions:


getProblem-Displays the user menu, then inputs and returns as the
function value the problem number selected.
get2Pt-Prompts the user for the x-y coordinates of both points, inputs
the four coordinates, and returns them to the calling function
through output parameters.
getPtS;Lope-Prompts the user for the slope and x-y coordinates of the
point, inputs the three values, and returns them to the calling func-
tion through output parameters.
slopelntcptFrom2Pt-Takes four input parameters, the x-y coordi-
nates of two points, and returns through output parameters the
slope (m) and y-intercept (b).
intcptFromPtSlope- Takes three input parameters, the x-y coordinates
of one point and the slope, and returns as the function value the
y-intercept.
display2Pt-Takes four input parameters, the x-y coordinates of two
points, and displays the two-point line equation with a heading.
displayPtSlope- Takes three input parameters, the x-y coordinates of
one point and the slope, and displays the point-slope line equation
with a heading.
displaySlopelntcpt-Takes two input parameters, the slope and y-
intercept, and displays the slope-intercept line equation with a heading.




Explanation / Answer

#include <iostream>
#include <iomanip>
using namespace std;

//PROTOTYPES
void getProblem(int&);
void get2Pt(double&, double&, double&, double&);
void getPtS(double&, double&, double&);
void slopelntcptFrom2Pt(double, double, double, double, double&, double&);
void intcptFromPtSlope(double, double, double, double&);
void display2Pt(double, double, double, double);
void displayPtSlope(double, double, double);
void displaySlopelntcpt(double, double);

int main()
{
   //LOCAL DECLARATIONS
   double x1, y1, x2, y2, m, b;
   int choice;
   char response = 'Y';

   while (toupper(response) == 'Y')
   {
      getProblem(choice);
      cout << endl;
      if (choice == 1)
      {
         get2Pt(x1, y1, x2, y2);
         slopelntcptFrom2Pt(x1, y1, x2, y2, m, b);
         cout << endl;
         display2Pt(x1, y1, x2, y2);
      }
      else
      {
         getPtS(x1, y1, m);
         intcptFromPtSlope(x1, y1, m, b);
         cout << endl;
         displayPtSlope(x1, y1, m);
      }
      cout << endl;
      displaySlopelntcpt(m, b);

      cout << " Do another conversion (Y or N) => ";
      cin >> response;
      cout << endl;
   }

   cout << endl;
   return 0;
}

//---------------------------------------------------------
// FUNCTION DEFINITIONS
//---------------------------------------------------------
void getProblem(int &choice)
{
   choice = 0;
   cout << "Select the form that you would like to convert to slope-intercept form: "
        << "1) Two-point form (you know two points on the line) "
        << "2) Point-slope form (you know the line's slope and one point) ";
   while (choice != 1 && choice != 2)
   {
      cout << "=> ";
      cin >> choice;
      if (choice != 1 && choice != 2)
         cout << "Enter 1 or 2 please ";
   }
}
//---------------------------------------------------------
void get2Pt(double &x1, double &y1, double &x2, double &y2)
{
   cout << "Enter the x-y coordinates of the first point separated by a space "
        << "=> ";
   cin >> x1 >> y1;
   cout << "Enter the x-y coordinates of the second point separated by a space "
        << "=> ";
   cin >> x2 >> y2;
}
//---------------------------------------------------------
void getPtS(double &x1, double &y1, double &m)
{
   cout << "Enter the slope=> ";
   cin >> m;
   cout << "Enter the x-y coordinates of the point separated by a space "
        << "=> ";
   cin >> x1 >> y1;
}
//---------------------------------------------------------
void slopelntcptFrom2Pt(double x1, double y1, double x2, double y2,
                        double &m, double &b)
{
   m = (y2 - y1) / (x2 - x1);
   b = y1 - m * x1;
}
//---------------------------------------------------------
void intcptFromPtSlope(double x1, double y1, double m,
                       double &b)
{
   b = y1 - m * x1;
}
//---------------------------------------------------------
void display2Pt(double x1, double y1, double x2, double y2)
{
   cout << "Two-point form ";
   cout << fixed << setprecision(2);
   cout << setw(5) << "("
        << y2 << (y1 > 0 ? " - " : " + ") << (y1 > 0 ? y1 : -y1)
        << ") ";
   cout << "m = ";
   cout << setw(5) << "("
        << x2 << (x1 > 0 ? " - " : " + ") << (x1 > 0 ? x1 : -x1)
        << ") ";
}
//---------------------------------------------------------
void displayPtSlope(double x1, double y1, double m)
{
   cout << "Point-slope form ";
   cout << fixed << setprecision(2);
   cout << "y " << (y1 > 0 ? "- " : "+ ") << (y1 > 0 ? y1 : -y1)
        << " = " << m << "(x "
        << (x1 > 0 ? "- " : "+ ") << (x1 > 0 ? x1 : -x1)
        << ") ";
}
//---------------------------------------------------------
void displaySlopelntcpt(double m, double b)
{
   cout << "Slope-intercept form ";
   cout << fixed << setprecision(2);
   cout << "y = " << m << "x "
        << (b > 0 ? "+ " : "- ") << (b > 0 ? b : -b) << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote