Question

C++ Code Needed for Lab! Let l be a line in the x-y plane. If l...

C++ Code Needed for Lab!

Let l be a line in the x-y plane. If l is a vertical line, its equation is x = a for some real number a.

Suppose l is not a vertical line and its slope is m. Then the equation of l is y = mx + b, where b is the y-intercept.

If l passes through the point (x₀, y₀), the equation of l can be written as y - y₀ = m(x - x₀).

If (x₁, y₁) and (x₂, y₂) are two points in the x-y plane and x₁ ≠ x₂, the slope of line passing through these points is m = (y₂ - y₁)/(x₂ - x₁).

Instructions

Write a C++ program that prompts the user for two points in the x-y plane. Input should be entered in the following order:

  • Input x₁
  • Input y₁
  • Input x₂
  • Input y₂

The program:

  1. Outputs the equation of the line
  2. Uses if statements to determine and output whether the line is vertical, horizontal, increasing, or decreasing.

If l is a non-vertical line, output its equation in the form y = mx + b.

Note: Output all numbers with a precision of two decimal places.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

int main()
{
    int x1,y1,x2,y2;
    float m,b;
    cin>>x1;
    cin>>y1;
    cin>>x2;
    cin>>y2;
    if(x1 == x2){
        cout<<"x = "<<x1<<endl;
    }
    else if(y1 == y2){
        cout<<"y = "<<y1<<endl;
    }
    else{
        m = (float)(y2-y1)/(x2-x1);
        b = y2 - m*x2;
        cout<<"y = "<<m<<"x + ("<<b<<")"<<endl;
    }

    return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ Code Needed for Lab! Let l be a line in the x-y plane. If l...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • --> Econ Graph Review a) The equation of the line passing through the points (5, 1)...

    --> Econ Graph Review a) The equation of the line passing through the points (5, 1) and (8, 2) is ay = x + b. Find the values for constants a and b. Represent this function in a xy plane. b) Let L be the line passing through the point (4, 9) with slope 3/4. Represent this function using the y = mx + b formula. Find the y-intercept of L. c) Graph the following two equations on the same...

  • A line is in the x y coordinate plane. The line is labeled g(x). The line...

    A line is in the x y coordinate plane. The line is labeled g(x). The line enters the viewing window in the second quadrant, goes down and to the right. As it travels, the line passes through the following points. (−5, 10) (−3, 4) (−5/3, 0) (−1, −2) (−2/3, −3) (0, −5) (2/3, −7) (1, −8) (5/3, −10) The line exits the window in the fourth quadrant. (a) Estimate g(1). g(1) = (b) Estimate g(−3). g(−3) = (c) Estimate x...

  • Please answer the two question 1. Write the equation of a line with the slope, 3/4,...

    Please answer the two question 1. Write the equation of a line with the slope, 3/4, which passes through the point (5,−4). Write the answer in slope-intercept form. 2.  Find the equation of the line that contains the point (23,36) and is parallel to the x-axis. Write the equation in the form y=mx+b and identify m and b

  • Find the slope of a line perpendicular to the line

    Find the slope of a line perpendicular to the line y=xUse the slope-intercept form of a linear equation to write the equation of each line with the given slope and y-intercept.slope -3; y-intercept (0, -1/5)write the equation of the line passing through the given points. write the equation in standard form Ax+By=C(8,-3) AND (4,-8)Write an equation of each line. Write the equation in the form x=a y=b or y =mx+bThrough (-2,-3): perpendicular to 3x+2y =5Find the equation of each line....

  • The Moulton Plane is the plane M = (R2, LM) such that a subset I of...

    The Moulton Plane is the plane M = (R2, LM) such that a subset I of R2 belongs to LM if and only if one of the following holds: i) l = {(x,y)| x=a} (vertical line); ii) l = {(x,y)| y=b} (horizontal line) iii) ( = {(x,y)| y = mx +b where m<0} (line with negative slope) [ m(x - x0) if x xo when m>0}. (bent line W 14,9 m ( x - x0) if x > xo with...

  • Problem 4: (a) (5 points) Find the equation for the line that passes through the points...

    Problem 4: (a) (5 points) Find the equation for the line that passes through the points (-4,-2) and (8, 1). Write your equation in se form, slope-intercept form, or point- slope form. (Extra Credit: Write the equation for the line in all three forms) (b) (5 points) Graph the line. Problem 5: (10 points) Find the equation for the line passing through the point (3.2) and perpendicular to the line y = ',x + 7. The the line Problem 6:...

  • of ARKANSAS AT PINE BLUFF NA DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE Linear Equations Name: 1....

    of ARKANSAS AT PINE BLUFF NA DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE Linear Equations Name: 1. Write the standard form equation of the line connecting the points (-2, 6) and (4,-4). 2. Write the slope-intercept form equation of the line connecting the points (-4, 4) and (4,10). Write the equation of a horizontal line passing through the point (7,-3). 4. Write the equation of a vertical line passing through the point (3,-7). 5. Write the standard form equation of the...

  • (MATLAB Question) I'm trying to create an equation of a line (y=mx+b) based on “x” with...

    (MATLAB Question) I'm trying to create an equation of a line (y=mx+b) based on “x” with slope m=2 and y-intercept 2. (y=2x+2). Then plot the line and turn hold on. This is what I have so far, I know something is wrong, but I am not sure at what part. Y=mx+b; Y=2x+2; m=2; y-intercept=2; (plot(x,y)) (plot hold on)

  • Ex-23. Construct three different programs (IPO diagram, pseudocode, flowchart) to compute the equation of a line...

    Ex-23. Construct three different programs (IPO diagram, pseudocode, flowchart) to compute the equation of a line expressed as y-mx+b, given (A) the coordinates of two points (x,y), (X2,Y2); where m is the slope and b the y intercept. (B) the coordinates of one point(x), and b (the y-intercept) (C) The slope "m" and the y-intercept, "b."

  • Hello, could someone please create me this MATLAB program GUI: - An example of the output...

    Hello, could someone please create me this MATLAB program GUI: - An example of the output is on the bottom *Please also generate a graph of the Equation y=mx+b upon pressing Calculate* Thank you Online calculator to find slope, length/distance, angle and equation of a line segment for entered the coordinates (X1, y1), (X2, y2) of two points, using following formula : m = (y2-71)/(x2-x1) and Distance = V((x2-x1)2 + (y2-71)2) Angle = arctan (m) and Line of Equation is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT